Skip to content

Commit

Permalink
Update samples.
Browse files Browse the repository at this point in the history
  • Loading branch information
yang-xiaodong committed Apr 18, 2024
1 parent 0c06336 commit fd81f3c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 19 deletions.
4 changes: 2 additions & 2 deletions samples/Sample.Kafka.PostgreSql/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddCap(x =>
{
//docker run --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword -d postgres
x.UsePostgreSql("User ID=postgres;Password=mysecretpassword;Host=localhost;Port=5432;Database=cap;");
x.UsePostgreSql("User ID=postgres;Password=mysecretpassword;Host=localhost;Port=5432;Database=postgres;");
//docker run --name kafka -p 9092:9092 -d bashj79/kafka-kraft
x.UseKafka("localhost:9092");
Expand All @@ -28,5 +28,5 @@ public void Configure(IApplicationBuilder app)
endpoints.MapControllers();
});
}
}
}
}
2 changes: 1 addition & 1 deletion samples/Sample.RabbitMQ.SqlServer/AppDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public override string ToString()

public class AppDbContext : DbContext
{
public const string ConnectionString = "Server=127.0.0.1;Database=AppDB;User Id=sa;Password=pass";
public const string ConnectionString = "Server=127.0.0.1;Database=tempdb;User Id=sa;Password=yourStrong(!)Password;TrustServerCertificate=True";

public DbSet<Person> Persons { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ await _capBus.PublishDelayAsync(TimeSpan.FromSeconds(delaySeconds), "sample.rabb
}

[Route("~/adonet/transaction")]
public IActionResult AdonetWithTransaction()
public async Task<IActionResult> AdonetWithTransaction()
{
using (var connection = new SqlConnection(AppDbContext.ConnectionString))
{
using (var transaction = connection.BeginTransaction(_capBus, true))
using (var transaction = await connection.BeginTransactionAsync(_capBus, true))
{
//your business code
connection.Execute("insert into test(name) values('test')", transaction: transaction);
await connection.ExecuteAsync("insert into test(name) values('test')", transaction: transaction);

_capBus.Publish("sample.rabbitmq.sqlserver", new Person()
await _capBus.PublishAsync("sample.rabbitmq.sqlserver", new Person()
{
Id = 123,
Name = "Bar"
Expand Down
16 changes: 5 additions & 11 deletions samples/Sample.RabbitMQ.SqlServer/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using DotNetCore.CAP;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace Sample.RabbitMQ.SqlServer
Expand All @@ -8,6 +7,7 @@ public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
//docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=yourStrong(!)Password" -e "MSSQL_PID=Evaluation" -p 1433:1433 --name sqlpreview --hostname sqlpreview -d mcr.microsoft.com/mssql/server:2022-preview-ubuntu-22.04
services.AddDbContext<AppDbContext>();

//services
Expand All @@ -17,17 +17,11 @@ public void ConfigureServices(IServiceCollection services)
services.AddCap(x =>
{
x.UseEntityFramework<AppDbContext>();
x.UseRabbitMQ(opt =>
{
opt.HostName = "localhost";
opt.BasicQosOptions = new RabbitMQOptions.BasicQos(1);
});
x.UseRabbitMQ("localhost");
x.UseDashboard();
//x.ConsumerThreadCount = 4;
x.EnableConsumerPrefetch = true;
x.EnablePublishParallelSend = true;
//x.FailedRetryCount = 5;
//x.UseDispatchingPerGroup = true;
//x.FailedThresholdCallback = failed =>
//{
// var logger = failed.ServiceProvider.GetRequiredService<ILogger<Startup>>();
Expand Down
2 changes: 1 addition & 1 deletion samples/Sample.RabbitMQ.SqlServer/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Logging": {
"LogLevel": {
"Default": "Error"
"Default": "Information"
}
}
}
2 changes: 2 additions & 0 deletions src/DotNetCore.CAP.PostgreSql/CAP.PostgreSqlOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public class PostgreSqlOptions : EFOptions
/// </summary>
internal NpgsqlConnection CreateConnection()
{
#pragma warning disable CS0618 // Type or member is obsolete
return DataSource != null ? DataSource.CreateConnection() : new NpgsqlConnection(ConnectionString);
#pragma warning restore CS0618 // Type or member is obsolete
}
}

Expand Down

0 comments on commit fd81f3c

Please sign in to comment.