diff --git a/samples/Sample.Pulsar.InMemory/Controllers/ValuesController.cs b/samples/Sample.Pulsar.InMemory/Controllers/ValuesController.cs new file mode 100644 index 0000000..5fa66bd --- /dev/null +++ b/samples/Sample.Pulsar.InMemory/Controllers/ValuesController.cs @@ -0,0 +1,32 @@ +using System; +using System.Threading.Tasks; +using DotNetCore.CAP; +using Microsoft.AspNetCore.Mvc; + +namespace Sample.Pulsar.InMemory.Controllers +{ + [Route("api/[controller]")] + public class ValuesController : Controller, ICapSubscribe + { + private readonly ICapPublisher _capBus; + + public ValuesController(ICapPublisher producer) + { + _capBus = producer; + } + + [Route("~/without/transaction")] + public async Task WithoutTransaction() + { + await _capBus.PublishAsync("persistent://public/default/captesttopic", DateTime.Now); + + return Ok(); + } + + [CapSubscribe("persistent://public/default/captesttopic")] + public void Test2T2(string value) + { + Console.WriteLine("Subscriber output message: " + value); + } + } +} \ No newline at end of file diff --git a/samples/Sample.Pulsar.InMemory/Program.cs b/samples/Sample.Pulsar.InMemory/Program.cs new file mode 100644 index 0000000..a5cd5cb --- /dev/null +++ b/samples/Sample.Pulsar.InMemory/Program.cs @@ -0,0 +1,20 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Hosting; + +namespace Sample.Pulsar.InMemory +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} \ No newline at end of file diff --git a/samples/Sample.Pulsar.InMemory/Sample.PulsarInMemory.csproj b/samples/Sample.Pulsar.InMemory/Sample.PulsarInMemory.csproj new file mode 100644 index 0000000..934396e --- /dev/null +++ b/samples/Sample.Pulsar.InMemory/Sample.PulsarInMemory.csproj @@ -0,0 +1,14 @@ + + + + netcoreapp3.1 + + + + + + + + + + diff --git a/samples/Sample.Pulsar.InMemory/Startup.cs b/samples/Sample.Pulsar.InMemory/Startup.cs new file mode 100644 index 0000000..e0bccfd --- /dev/null +++ b/samples/Sample.Pulsar.InMemory/Startup.cs @@ -0,0 +1,38 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace Sample.Pulsar.InMemory +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + public void ConfigureServices(IServiceCollection services) + { + string pulsarUri = Configuration.GetValue("AppSettings:PulsarUri", "pulsar//localhost:6650"); + services.AddCap(x => + { + x.UseInMemoryStorage(); + x.UsePulsar(pulsarUri); + x.UseDashboard(); + }); + + services.AddControllers(); + } + + public void Configure(IApplicationBuilder app) + { + app.UseRouting(); + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} \ No newline at end of file diff --git a/samples/Sample.Pulsar.InMemory/appsettings.json b/samples/Sample.Pulsar.InMemory/appsettings.json new file mode 100644 index 0000000..106974b --- /dev/null +++ b/samples/Sample.Pulsar.InMemory/appsettings.json @@ -0,0 +1,12 @@ +{ + "Logging": { + "IncludeScopes": false, + "LogLevel": { + "Default": "Debug" + } + }, + "AppSettings": { + "PulsarUri": "pulsar://10.9.1.124:30398,10.9.1.124:30724,10.9.1.124:31771", + "PulsarTopic": "persistent://public/default/captesttopic" + } +}