Commit 13274160 authored by yangxiaodong's avatar yangxiaodong

update samples.

parent 04572d38
...@@ -10,7 +10,8 @@ namespace Sample.RabbitMQ.MySql ...@@ -10,7 +10,8 @@ namespace Sample.RabbitMQ.MySql
{ {
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{ {
optionsBuilder.UseMySql("Server=localhost;Database=Sample.RabbitMQ.MySql;UserId=root;Password=123123;"); //optionsBuilder.UseMySql("Server=localhost;Database=Sample.RabbitMQ.MySql;UserId=root;Password=123123;");
optionsBuilder.UseMySql("Server=192.168.2.206;Database=Sample.RabbitMQ.MySql;UserId=root;Password=123123;");
} }
} }
} }
...@@ -43,18 +43,17 @@ namespace Sample.RabbitMQ.MySql.Controllers ...@@ -43,18 +43,17 @@ namespace Sample.RabbitMQ.MySql.Controllers
using (var trans = await _dbContext.Database.BeginTransactionAsync()) using (var trans = await _dbContext.Database.BeginTransactionAsync())
{ {
await _capBus.PublishAsync("sample.kafka.sqlserver", ""); await _capBus.PublishAsync("sample.kafka.sqlserver", "");
trans.Commit(); trans.Commit();
} }
return Ok(); return Ok();
} }
[NonAction] [NonAction]
[CapSubscribe("sample.rabbitmq.mysql")] [CapSubscribe("sample.rabbitmq.mysql")]
public void ReceiveMessage() public void ReceiveMessage(DateTime time)
{ {
Console.WriteLine("[sample.rabbitmq.mysql] message received"); Console.WriteLine("[sample.rabbitmq.mysql] message received: "+ DateTime.Now.ToString() +" , sent time: " + time.ToString());
Debug.WriteLine("[sample.rabbitmq.mysql] message received");
} }
} }
} }
...@@ -17,13 +17,13 @@ ...@@ -17,13 +17,13 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="2.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.0.0-preview3-10055" /> <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.0.0-rtm-10056" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" /> <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\src\DotNetCore.CAP.PostgreSql\DotNetCore.CAP.PostgreSql.csproj" /> <ProjectReference Include="..\..\src\DotNetCore.CAP.MySql\DotNetCore.CAP.MySql.csproj" />
<ProjectReference Include="..\..\src\DotNetCore.CAP.RabbitMQ\DotNetCore.CAP.RabbitMQ.csproj" /> <ProjectReference Include="..\..\src\DotNetCore.CAP.RabbitMQ\DotNetCore.CAP.RabbitMQ.csproj" />
<ProjectReference Include="..\..\src\DotNetCore.CAP\DotNetCore.CAP.csproj" /> <ProjectReference Include="..\..\src\DotNetCore.CAP\DotNetCore.CAP.csproj" />
</ItemGroup> </ItemGroup>
......
...@@ -18,7 +18,11 @@ namespace Sample.RabbitMQ.MySql ...@@ -18,7 +18,11 @@ namespace Sample.RabbitMQ.MySql
services.AddCap(x => services.AddCap(x =>
{ {
x.UseEntityFramework<AppDbContext>(); x.UseEntityFramework<AppDbContext>();
x.UseRabbitMQ("localhost"); x.UseRabbitMQ(y => {
y.HostName = "192.168.2.206";
y.UserName = "admin";
y.Password = "123123";
});
}); });
services.AddMvc(); services.AddMvc();
......
...@@ -16,6 +16,7 @@ namespace Sample.RabbitMQ.PostgreSql ...@@ -16,6 +16,7 @@ namespace Sample.RabbitMQ.PostgreSql
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddMvc(); services.AddMvc();
} }
......
...@@ -6,7 +6,7 @@ namespace Sample.RabbitMQ.SqlServer ...@@ -6,7 +6,7 @@ namespace Sample.RabbitMQ.SqlServer
{ {
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{ {
//optionsBuilder.UseSqlServer("Server=192.168.2.206;Initial Catalog=Test;User Id=cmswuliu;Password=h7xY81agBn*Veiu3;MultipleActiveResultSets=True"); optionsBuilder.UseSqlServer("Server=192.168.2.206;Initial Catalog=TestCap;User Id=cmswuliu;Password=h7xY81agBn*Veiu3;MultipleActiveResultSets=True");
//optionsBuilder.UseSqlServer("Server=DESKTOP-M9R8T31;Initial Catalog=Sample.Kafka.SqlServer;User Id=sa;Password=P@ssw0rd;MultipleActiveResultSets=True"); //optionsBuilder.UseSqlServer("Server=DESKTOP-M9R8T31;Initial Catalog=Sample.Kafka.SqlServer;User Id=sa;Password=P@ssw0rd;MultipleActiveResultSets=True");
} }
} }
......
...@@ -6,6 +6,18 @@ using Microsoft.AspNetCore.Mvc; ...@@ -6,6 +6,18 @@ using Microsoft.AspNetCore.Mvc;
namespace Sample.RabbitMQ.SqlServer.Controllers namespace Sample.RabbitMQ.SqlServer.Controllers
{ {
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
public override string ToString()
{
return "Name:" + Name + ";Age:" + Age;
}
}
[Route("api/[controller]")] [Route("api/[controller]")]
public class ValuesController : Controller, ICapSubscribe public class ValuesController : Controller, ICapSubscribe
{ {
...@@ -21,8 +33,12 @@ namespace Sample.RabbitMQ.SqlServer.Controllers ...@@ -21,8 +33,12 @@ namespace Sample.RabbitMQ.SqlServer.Controllers
[Route("~/publish")] [Route("~/publish")]
public IActionResult PublishMessage() public IActionResult PublishMessage()
{ {
_capBus.Publish("sample.rabbitmq.mysql", ""); using(var trans = _dbContext.Database.BeginTransaction())
{
//_capBus.Publish("sample.rabbitmq.mysql22222", DateTime.Now);
_capBus.Publish("sample.rabbitmq.mysql33333", new Person { Name = "宜兴", Age = 11 });
trans.Commit();
}
return Ok(); return Ok();
} }
...@@ -32,12 +48,38 @@ namespace Sample.RabbitMQ.SqlServer.Controllers ...@@ -32,12 +48,38 @@ namespace Sample.RabbitMQ.SqlServer.Controllers
using (var trans = await _dbContext.Database.BeginTransactionAsync()) using (var trans = await _dbContext.Database.BeginTransactionAsync())
{ {
await _capBus.PublishAsync("sample.rabbitmq.mysql", ""); await _capBus.PublishAsync("sample.rabbitmq.mysql", "");
trans.Commit(); trans.Commit();
} }
return Ok(); return Ok();
} }
[CapSubscribe("sample.rabbitmq.mysql33333")]
public void KafkaTest22(Person person)
{
var aa = _dbContext.Database;
_dbContext.Dispose();
Console.WriteLine("[sample.kafka.sqlserver] message received " + person.ToString());
Debug.WriteLine("[sample.kafka.sqlserver] message received " + person.ToString());
}
//[CapSubscribe("sample.rabbitmq.mysql22222")]
//public void KafkaTest22(DateTime time)
//{
// Console.WriteLine("[sample.kafka.sqlserver] message received " + time.ToString());
// Debug.WriteLine("[sample.kafka.sqlserver] message received " + time.ToString());
//}
[CapSubscribe("sample.rabbitmq.mysql22222")]
public async Task<DateTime> KafkaTest33(DateTime time)
{
Console.WriteLine("[sample.kafka.sqlserver] message received " + time.ToString());
Debug.WriteLine("[sample.kafka.sqlserver] message received " + time.ToString());
return await Task.FromResult(time);
}
[NonAction] [NonAction]
[CapSubscribe("sample.kafka.sqlserver3")] [CapSubscribe("sample.kafka.sqlserver3")]
[CapSubscribe("sample.kafka.sqlserver4")] [CapSubscribe("sample.kafka.sqlserver4")]
......
...@@ -14,7 +14,11 @@ namespace Sample.RabbitMQ.SqlServer ...@@ -14,7 +14,11 @@ namespace Sample.RabbitMQ.SqlServer
services.AddCap(x => services.AddCap(x =>
{ {
x.UseEntityFramework<AppDbContext>(); x.UseEntityFramework<AppDbContext>();
x.UseRabbitMQ("localhost"); x.UseRabbitMQ(y=> {
y.HostName = "192.168.2.206";
y.UserName = "admin";
y.Password = "123123";
});
}); });
services.AddMvc(); services.AddMvc();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment