@@ -35,7 +35,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetCore.CAP", "src\DotNe | |||||
EndProject | EndProject | ||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{3A6B6931-A123-477A-9469-8B468B5385AF}" | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{3A6B6931-A123-477A-9469-8B468B5385AF}" | ||||
EndProject | EndProject | ||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.Kafka", "samples\Sample.Kafka\Sample.Kafka.csproj", "{2F095ED9-5BC9-4512-9013-A47685FB2508}" | |||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.Kafka.SqlServer", "samples\Sample.Kafka\Sample.Kafka.SqlServer.csproj", "{2F095ED9-5BC9-4512-9013-A47685FB2508}" | |||||
EndProject | EndProject | ||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetCore.CAP.Kafka", "src\DotNetCore.CAP.Kafka\DotNetCore.CAP.Kafka.csproj", "{C42CDE33-0878-4BA0-96F2-4CB7C8FDEAAD}" | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetCore.CAP.Kafka", "src\DotNetCore.CAP.Kafka\DotNetCore.CAP.Kafka.csproj", "{C42CDE33-0878-4BA0-96F2-4CB7C8FDEAAD}" | ||||
EndProject | EndProject | ||||
@@ -63,6 +63,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetCore.CAP.MySql", "src | |||||
EndProject | EndProject | ||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetCore.CAP.MySql.Test", "test\DotNetCore.CAP.MySql.Test\DotNetCore.CAP.MySql.Test.csproj", "{80A84F62-1558-427B-BA74-B47AA8A665B5}" | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetCore.CAP.MySql.Test", "test\DotNetCore.CAP.MySql.Test\DotNetCore.CAP.MySql.Test.csproj", "{80A84F62-1558-427B-BA74-B47AA8A665B5}" | ||||
EndProject | EndProject | ||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.RabbitMQ.MySql", "samples\Sample.RabbitMQ.MySql\Sample.RabbitMQ.MySql.csproj", "{9F3F9BFE-7B6A-4A7A-A6E6-8B517D611873}" | |||||
EndProject | |||||
Global | Global | ||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||||
Debug|Any CPU = Debug|Any CPU | Debug|Any CPU = Debug|Any CPU | ||||
@@ -104,6 +106,10 @@ Global | |||||
{80A84F62-1558-427B-BA74-B47AA8A665B5}.Debug|Any CPU.Build.0 = Debug|Any CPU | {80A84F62-1558-427B-BA74-B47AA8A665B5}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
{80A84F62-1558-427B-BA74-B47AA8A665B5}.Release|Any CPU.ActiveCfg = Release|Any CPU | {80A84F62-1558-427B-BA74-B47AA8A665B5}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||
{80A84F62-1558-427B-BA74-B47AA8A665B5}.Release|Any CPU.Build.0 = Release|Any CPU | {80A84F62-1558-427B-BA74-B47AA8A665B5}.Release|Any CPU.Build.0 = Release|Any CPU | ||||
{9F3F9BFE-7B6A-4A7A-A6E6-8B517D611873}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||||
{9F3F9BFE-7B6A-4A7A-A6E6-8B517D611873}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||||
{9F3F9BFE-7B6A-4A7A-A6E6-8B517D611873}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||||
{9F3F9BFE-7B6A-4A7A-A6E6-8B517D611873}.Release|Any CPU.Build.0 = Release|Any CPU | |||||
EndGlobalSection | EndGlobalSection | ||||
GlobalSection(SolutionProperties) = preSolution | GlobalSection(SolutionProperties) = preSolution | ||||
HideSolutionNode = FALSE | HideSolutionNode = FALSE | ||||
@@ -119,5 +125,6 @@ Global | |||||
{DA00FA38-C4B9-4F55-8756-D480FBC1084F} = {C09CDAB0-6DD4-46E9-B7F3-3EF2A4741EA0} | {DA00FA38-C4B9-4F55-8756-D480FBC1084F} = {C09CDAB0-6DD4-46E9-B7F3-3EF2A4741EA0} | ||||
{FA15685A-778A-4D2A-A2FE-27FAD2FFA65B} = {9B2AE124-6636-4DE9-83A3-70360DABD0C4} | {FA15685A-778A-4D2A-A2FE-27FAD2FFA65B} = {9B2AE124-6636-4DE9-83A3-70360DABD0C4} | ||||
{80A84F62-1558-427B-BA74-B47AA8A665B5} = {C09CDAB0-6DD4-46E9-B7F3-3EF2A4741EA0} | {80A84F62-1558-427B-BA74-B47AA8A665B5} = {C09CDAB0-6DD4-46E9-B7F3-3EF2A4741EA0} | ||||
{9F3F9BFE-7B6A-4A7A-A6E6-8B517D611873} = {3A6B6931-A123-477A-9469-8B468B5385AF} | |||||
EndGlobalSection | EndGlobalSection | ||||
EndGlobal | EndGlobal |
@@ -1,7 +1,7 @@ | |||||
using System; | using System; | ||||
using System.Diagnostics; | |||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
using DotNetCore.CAP; | using DotNetCore.CAP; | ||||
using Microsoft.AspNetCore.Hosting; | |||||
using Microsoft.AspNetCore.Mvc; | using Microsoft.AspNetCore.Mvc; | ||||
namespace Sample.Kafka.Controllers | namespace Sample.Kafka.Controllers | ||||
@@ -9,46 +9,39 @@ namespace Sample.Kafka.Controllers | |||||
[Route("api/[controller]")] | [Route("api/[controller]")] | ||||
public class ValuesController : Controller, ICapSubscribe | public class ValuesController : Controller, ICapSubscribe | ||||
{ | { | ||||
private readonly ICapPublisher _producer; | |||||
private readonly AppDbContext _dbContext ; | |||||
private readonly ICapPublisher _capBus; | |||||
private readonly AppDbContext _dbContext; | |||||
public ValuesController(ICapPublisher producer, AppDbContext dbContext) | public ValuesController(ICapPublisher producer, AppDbContext dbContext) | ||||
{ | { | ||||
_producer = producer; | |||||
_capBus = producer; | |||||
_dbContext = dbContext; | _dbContext = dbContext; | ||||
} | } | ||||
[Route("/")] | |||||
public IActionResult Index() | |||||
[Route("~/publish")] | |||||
public IActionResult PublishMessage() | |||||
{ | { | ||||
_capBus.Publish("sample.rabbitmq.mysql", ""); | |||||
return Ok(); | return Ok(); | ||||
} | } | ||||
public string ServerPath => ((IHostingEnvironment)HttpContext.RequestServices.GetService(typeof(IHostingEnvironment))).ContentRootPath; | |||||
[CapSubscribe("zzwl.topic.finace.callBack", Group = "test")] | |||||
public void KafkaTest(Person person) | |||||
[Route("~/publishWithTrans")] | |||||
public async Task<IActionResult> PublishMessageWithTransaction() | |||||
{ | { | ||||
Console.WriteLine(DateTime.Now); | |||||
} | |||||
[Route("~/send")] | |||||
public async Task<IActionResult> SendTopic() | |||||
{ | |||||
using (var trans = _dbContext.Database.BeginTransaction()) | |||||
using (var trans = await _dbContext.Database.BeginTransactionAsync()) | |||||
{ | { | ||||
await _producer.PublishAsync("zzwl.topic.finace.callBack",""); | |||||
await _capBus.PublishAsync("sample.rabbitmq.mysql", ""); | |||||
trans.Commit(); | trans.Commit(); | ||||
} | } | ||||
return Ok(); | return Ok(); | ||||
} | } | ||||
public class Person | |||||
[NonAction] | |||||
[CapSubscribe("sample.kafka.sqlserver", Group = "test")] | |||||
public void KafkaTest() | |||||
{ | { | ||||
public string Name { get; set; } | |||||
public int Age { get; set; } | |||||
Console.WriteLine("[sample.kafka.sqlserver] message received"); | |||||
Debug.WriteLine("[sample.kafka.sqlserver] message received"); | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -1,13 +1,21 @@ | |||||
using System.IO; | using System.IO; | ||||
using Microsoft.AspNetCore.Builder; | using Microsoft.AspNetCore.Builder; | ||||
using Microsoft.AspNetCore.Hosting; | using Microsoft.AspNetCore.Hosting; | ||||
using Microsoft.Extensions.Configuration; | |||||
namespace Sample.Kafka | namespace Sample.Kafka | ||||
{ | { | ||||
public class Program | public class Program | ||||
{ | { | ||||
public static void Main(string[] args) { | |||||
public static void Main(string[] args) | |||||
{ | |||||
var config = new ConfigurationBuilder() | |||||
.AddCommandLine(args) | |||||
.AddEnvironmentVariables("ASPNETCORE_") | |||||
.Build(); | |||||
var host = new WebHostBuilder() | var host = new WebHostBuilder() | ||||
.UseConfiguration(config) | |||||
.UseKestrel() | .UseKestrel() | ||||
.UseContentRoot(Directory.GetCurrentDirectory()) | .UseContentRoot(Directory.GetCurrentDirectory()) | ||||
.UseIISIntegration() | .UseIISIntegration() | ||||
@@ -2,14 +2,9 @@ | |||||
<PropertyGroup> | <PropertyGroup> | ||||
<TargetFramework>netcoreapp1.1</TargetFramework> | <TargetFramework>netcoreapp1.1</TargetFramework> | ||||
<AssemblyName>Sample.Kafka.SqlServer</AssemblyName> | |||||
</PropertyGroup> | </PropertyGroup> | ||||
<ItemGroup> | |||||
<Compile Remove="wwwroot\**" /> | |||||
<Content Remove="wwwroot\**" /> | |||||
<EmbeddedResource Remove="wwwroot\**" /> | |||||
<None Remove="wwwroot\**" /> | |||||
</ItemGroup> | |||||
<ItemGroup> | <ItemGroup> | ||||
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" /> | <PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" /> | ||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" /> | <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" /> | ||||
@@ -17,6 +12,7 @@ | |||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.2" /> | <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.2" /> | ||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.2" /> | <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.2" /> | ||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.1" /> | <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.1" /> | ||||
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="1.1.2" /> | |||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" /> | <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> |
@@ -1,6 +1,5 @@ | |||||
using Microsoft.AspNetCore.Builder; | using Microsoft.AspNetCore.Builder; | ||||
using Microsoft.AspNetCore.Hosting; | using Microsoft.AspNetCore.Hosting; | ||||
using Microsoft.Extensions.Configuration; | |||||
using Microsoft.Extensions.DependencyInjection; | using Microsoft.Extensions.DependencyInjection; | ||||
using Microsoft.Extensions.Logging; | using Microsoft.Extensions.Logging; | ||||
@@ -8,19 +7,6 @@ namespace Sample.Kafka | |||||
{ | { | ||||
public class Startup | public class Startup | ||||
{ | { | ||||
public Startup(IHostingEnvironment env) | |||||
{ | |||||
var builder = new ConfigurationBuilder() | |||||
.SetBasePath(env.ContentRootPath) | |||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) | |||||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) | |||||
.AddEnvironmentVariables(); | |||||
Configuration = builder.Build(); | |||||
} | |||||
public IConfigurationRoot Configuration { get; } | |||||
// 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.AddDbContext<AppDbContext>(); | services.AddDbContext<AppDbContext>(); | ||||
@@ -28,18 +14,15 @@ namespace Sample.Kafka | |||||
services.AddCap(x => | services.AddCap(x => | ||||
{ | { | ||||
x.UseEntityFramework<AppDbContext>(); | x.UseEntityFramework<AppDbContext>(); | ||||
//x.UseSqlServer("Server=DESKTOP-M9R8T31;Initial Catalog=Test;User Id=sa;Password=P@ssw0rd;MultipleActiveResultSets=True"); | |||||
x.UseKafka("localhost:9092"); | x.UseKafka("localhost:9092"); | ||||
}); | }); | ||||
// Add framework services. | |||||
services.AddMvc(); | services.AddMvc(); | ||||
} | } | ||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | |||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) | public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) | ||||
{ | { | ||||
loggerFactory.AddConsole(Configuration.GetSection("Logging")); | |||||
loggerFactory.AddConsole(); | |||||
loggerFactory.AddDebug(); | loggerFactory.AddDebug(); | ||||
app.UseMvc(); | app.UseMvc(); | ||||
@@ -1,10 +0,0 @@ | |||||
{ | |||||
"Logging": { | |||||
"IncludeScopes": false, | |||||
"LogLevel": { | |||||
"Default": "Debug", | |||||
"System": "Information", | |||||
"Microsoft": "Information" | |||||
} | |||||
} | |||||
} |
@@ -1,8 +0,0 @@ | |||||
{ | |||||
"Logging": { | |||||
"IncludeScopes": false, | |||||
"LogLevel": { | |||||
"Default": "Warning" | |||||
} | |||||
} | |||||
} |