diff --git a/samples/Sample.Kafka.MySql/Controllers/ValuesController.cs b/samples/Sample.Kafka.MySql/Controllers/ValuesController.cs index 361c606..9535b1d 100644 --- a/samples/Sample.Kafka.MySql/Controllers/ValuesController.cs +++ b/samples/Sample.Kafka.MySql/Controllers/ValuesController.cs @@ -1,8 +1,11 @@ using System; +using System.Data; +using System.Data.SqlClient; +using System.Transactions; using Dapper; using DotNetCore.CAP; using Microsoft.AspNetCore.Mvc; -using MySql.Data.MySqlClient; +//using MySql.Data.MySqlClient; namespace Sample.Kafka.MySql.Controllers { @@ -28,17 +31,14 @@ namespace Sample.Kafka.MySql.Controllers public IActionResult AdonetWithTransaction() { //NOTE: Add `IgnoreCommandTransaction=true;` to your connection string, see https://github.com/mysql-net/MySqlConnector/issues/474 - using (var connection = new MySqlConnection(Startup.ConnectionString)) + using (var connection = new SqlConnection(Startup.ConnectionString)) { - using (var transaction = connection.BeginAndJoinToTransaction(_capBus, autoCommit: false)) + using (var transaction = connection.BeginTransaction(_capBus, autoCommit: false)) { //your business code - connection.Execute("insert into test(name) values('test')", transaction); + connection.Execute("insert into dbo.test1(tname) values('test');", transaction: (IDbTransaction)transaction.DbTransaction); - for (int i = 0; i < 5; i++) - { - _capBus.Publish("sample.rabbitmq.mysql", DateTime.Now); - } + _capBus.Publish("sample.rabbitmq.mysql", DateTime.Now); transaction.Commit(); } diff --git a/samples/Sample.Kafka.MySql/Startup.cs b/samples/Sample.Kafka.MySql/Startup.cs index 9ff4345..583a416 100644 --- a/samples/Sample.Kafka.MySql/Startup.cs +++ b/samples/Sample.Kafka.MySql/Startup.cs @@ -6,13 +6,15 @@ namespace Sample.Kafka.MySql public class Startup { public const string ConnectionString = "Server=localhost;Database=testcap;UserId=root;Password=123123;"; + //public const string ConnectionString = "Server=(localdb)\\ProjectsV13;Integrated Security=SSPI;Database=testcap"; public void ConfigureServices(IServiceCollection services) { services.AddCap(x => { x.UseMySql(ConnectionString); - x.UseKafka("localhost:9092"); + //x.UseSqlServer(ConnectionString); + x.UseKafka("192.168.10.110:9092"); x.UseDashboard(); }); diff --git a/samples/Sample.RabbitMQ.MongoDB/Controllers/ValuesController.cs b/samples/Sample.RabbitMQ.MongoDB/Controllers/ValuesController.cs index c811c83..067b6d4 100644 --- a/samples/Sample.RabbitMQ.MongoDB/Controllers/ValuesController.cs +++ b/samples/Sample.RabbitMQ.MongoDB/Controllers/ValuesController.cs @@ -35,7 +35,7 @@ namespace Sample.RabbitMQ.MongoDB.Controllers //var mycollection = _client.GetDatabase("test").GetCollection("test.collection"); //mycollection.InsertOne(new BsonDocument { { "test", "test" } }); - using (var session = _client.StartAndJoinToTransaction(_capBus, autoCommit: false)) + using (var session = _client.StartTransaction(_capBus, autoCommit: false)) { var collection = _client.GetDatabase("test").GetCollection("test.collection"); collection.InsertOne(session, new BsonDocument { { "hello", "world" } }); @@ -55,7 +55,7 @@ namespace Sample.RabbitMQ.MongoDB.Controllers //var mycollection = _client.GetDatabase("test").GetCollection("test.collection"); //mycollection.InsertOne(new BsonDocument { { "test", "test" } }); - using (var session = _client.StartAndJoinToTransaction(_capBus, autoCommit: true)) + using (var session = _client.StartTransaction(_capBus, autoCommit: true)) { var collection = _client.GetDatabase("test").GetCollection("test.collection"); collection.InsertOne(session, new BsonDocument { { "hello", "world" } }); diff --git a/samples/Sample.RabbitMQ.MySql/Controllers/ValuesController.cs b/samples/Sample.RabbitMQ.MySql/Controllers/ValuesController.cs index 7f31680..9fa3b82 100644 --- a/samples/Sample.RabbitMQ.MySql/Controllers/ValuesController.cs +++ b/samples/Sample.RabbitMQ.MySql/Controllers/ValuesController.cs @@ -1,4 +1,5 @@ using System; +using System.Data; using Dapper; using DotNetCore.CAP; using Microsoft.AspNetCore.Mvc; @@ -30,10 +31,10 @@ namespace Sample.RabbitMQ.MySql.Controllers //NOTE: Add `IgnoreCommandTransaction=true;` to your connection string, see https://github.com/mysql-net/MySqlConnector/issues/474 using (var connection = new MySqlConnection(AppDbContext.ConnectionString)) { - using (var transaction = connection.BeginAndJoinToTransaction(_capBus, autoCommit: false)) + using (var transaction = connection.BeginTransaction(_capBus, autoCommit: false)) { //your business code - connection.Execute("insert into test(name) values('test')", transaction); + connection.Execute("insert into test(name) values('test')", transaction: (IDbTransaction)transaction.DbTransaction); for (int i = 0; i < 5; i++) { @@ -50,7 +51,7 @@ namespace Sample.RabbitMQ.MySql.Controllers [Route("~/ef/transaction")] public IActionResult EntityFrameworkWithTransaction([FromServices]AppDbContext dbContext) { - using (var trans = dbContext.Database.BeginAndJoinToTransaction(_capBus, autoCommit: false)) + using (var trans = dbContext.Database.BeginTransaction(_capBus, autoCommit: false)) { dbContext.Persons.Add(new Person() { Name = "ef.transaction" });