ソースを参照

update samples

master
Savorboard 6年前
コミット
dae03f33b7
4個のファイルの変更17行の追加14行の削除
  1. +8
    -8
      samples/Sample.Kafka.MySql/Controllers/ValuesController.cs
  2. +3
    -1
      samples/Sample.Kafka.MySql/Startup.cs
  3. +2
    -2
      samples/Sample.RabbitMQ.MongoDB/Controllers/ValuesController.cs
  4. +4
    -3
      samples/Sample.RabbitMQ.MySql/Controllers/ValuesController.cs

+ 8
- 8
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();
}


+ 3
- 1
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();
});



+ 2
- 2
samples/Sample.RabbitMQ.MongoDB/Controllers/ValuesController.cs ファイルの表示

@@ -35,7 +35,7 @@ namespace Sample.RabbitMQ.MongoDB.Controllers
//var mycollection = _client.GetDatabase("test").GetCollection<BsonDocument>("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<BsonDocument>("test.collection");
collection.InsertOne(session, new BsonDocument { { "hello", "world" } });
@@ -55,7 +55,7 @@ namespace Sample.RabbitMQ.MongoDB.Controllers
//var mycollection = _client.GetDatabase("test").GetCollection<BsonDocument>("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<BsonDocument>("test.collection");
collection.InsertOne(session, new BsonDocument { { "hello", "world" } });


+ 4
- 3
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" });



読み込み中…
キャンセル
保存