Browse Source

adding sample

master
Christian Pauli 4 years ago
parent
commit
8c6332e7ed
5 changed files with 116 additions and 0 deletions
  1. +32
    -0
      samples/Sample.Pulsar.InMemory/Controllers/ValuesController.cs
  2. +20
    -0
      samples/Sample.Pulsar.InMemory/Program.cs
  3. +14
    -0
      samples/Sample.Pulsar.InMemory/Sample.PulsarInMemory.csproj
  4. +38
    -0
      samples/Sample.Pulsar.InMemory/Startup.cs
  5. +12
    -0
      samples/Sample.Pulsar.InMemory/appsettings.json

+ 32
- 0
samples/Sample.Pulsar.InMemory/Controllers/ValuesController.cs View File

@@ -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<IActionResult> 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);
}
}
}

+ 20
- 0
samples/Sample.Pulsar.InMemory/Program.cs View File

@@ -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<Startup>();
});
}
}

+ 14
- 0
samples/Sample.Pulsar.InMemory/Sample.PulsarInMemory.csproj View File

@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\DotNetCore.CAP.Dashboard\DotNetCore.CAP.Dashboard.csproj" />
<ProjectReference Include="..\..\src\DotNetCore.CAP.InMemoryStorage\DotNetCore.CAP.InMemoryStorage.csproj" />
<ProjectReference Include="..\..\src\DotNetCore.CAP.Pulsar\DotNetCore.CAP.Pulsar.csproj" />
<ProjectReference Include="..\..\src\DotNetCore.CAP\DotNetCore.CAP.csproj" />
</ItemGroup>

</Project>

+ 38
- 0
samples/Sample.Pulsar.InMemory/Startup.cs View File

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

+ 12
- 0
samples/Sample.Pulsar.InMemory/appsettings.json View File

@@ -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"
}
}

Loading…
Cancel
Save