Skip to content

Commit 43154a6

Browse files
Add sample for tickerQ (#4038)
* add tickerq sample * adding some updates and readme * update ef tools version * use the default mapper * fix missing packages --------- Co-authored-by: Ian Cooper <ian_hammond_cooper@yahoo.co.uk>
1 parent bdc1888 commit 43154a6

28 files changed

Lines changed: 1287 additions & 0 deletions

Brighter.slnx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
<Project Path="samples/Scheduler/QuartzTaskQueue/GreetingsPumper/GreetingsPumper.csproj" />
2626
<Project Path="samples/Scheduler/QuartzTaskQueue/GreetingsReceiverConsole/GreetingsReceiverConsole.csproj" />
2727
</Folder>
28+
<Folder Name="/samples/Scheduler/TickerQ/">
29+
<File Path="samples/Scheduler/TickerQ/README.md" />
30+
<Project Path="samples/Scheduler/TickerQ/Greeting.AppHost/Greeting.AppHost.csproj" />
31+
<Project Path="samples/Scheduler/TickerQ/Greeting.Consumer/Greeting.Consumer.csproj" />
32+
<Project Path="samples/Scheduler/TickerQ/Greeting.Models/Greeting.Models.csproj" />
33+
<Project Path="samples/Scheduler/TickerQ/Greeting.Producer/Greeting.Producer.csproj" />
34+
<Project Path="samples/Scheduler/TickerQ/Greeting.ServiceDefaults/Greeting.ServiceDefaults.csproj" />
35+
</Folder>
2836
<Folder Name="/samples/TaskQueue/" />
2937
<Folder Name="/samples/TaskQueue/ASBTaskQueue/">
3038
<Project Path="samples/TaskQueue/ASBTaskQueue/Greetings/Greetings.csproj" />

Directory.Packages.props

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
<RabbitMQClientV6>6.8.1</RabbitMQClientV6>
1414
</PropertyGroup>
1515
<ItemGroup>
16+
<PackageVersion Include="Aspire.Hosting.AppHost" Version="13.1.2" />
17+
<PackageVersion Include="Aspire.Hosting.RabbitMQ" Version="13.1.2" />
1618
<PackageVersion Include="AWSSDK.DynamoDBv2" Version="[3.7.500.5, 4)" />
1719
<PackageVersion Include="AWSSDK.IdentityManagement" Version="[3.7.500.5, 4)" />
1820
<PackageVersion Include="AWSSDK.Extensions.NETCore.Setup" Version="[3.7.400, 4)" />
@@ -107,6 +109,8 @@
107109
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.15.2" />
108110
<PackageVersion Include="OpenTelemetry.Exporter.Prometheus.AspNetCore" Version="1.14.0-beta.1" />
109111
<PackageVersion Include="OpenTelemetry.Exporter.Zipkin" Version="1.14.0" />
112+
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.15.0"/>
113+
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.15.0"/>
110114
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.15.2" />
111115
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.15.1" />
112116
<PackageVersion Include="Paramore.Darker" Version="4.1.1" />
@@ -155,24 +159,30 @@
155159
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.22" />
156160
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.22" />
157161
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.22" />
162+
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.22" />
158163
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="8.0.22" />
159164
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.22" />
160165
<PackageVersion Include="MongoDB.EntityFrameworkCore" Version="8.3.3" />
161166
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.3" />
162167
<PackageVersion Include="Npgsql" Version="8.0.7" />
163168
<PackageVersion Include="TickerQ" Version="8.0.0" />
169+
<PackageVersion Include="TickerQ.Dashboard" Version="8.0.0" />
170+
<PackageVersion Include="TickerQ.EntityFrameworkCore" Version="8.0.0" />
164171
</ItemGroup>
165172
<ItemGroup Condition=" '$(TargetFramework)' == 'net9.0' ">
166173
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="9.0.11" />
167174
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.11" />
168175
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.11" />
169176
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.11" />
177+
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.11" />
170178
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="9.0.11" />
171179
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.11" />
172180
<PackageVersion Include="MongoDB.EntityFrameworkCore" Version="9.0.3" />
173181
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0" />
174182
<PackageVersion Include="Npgsql" Version="10.0.1" />
175183
<PackageVersion Include="TickerQ" Version="9.0.0" />
184+
<PackageVersion Include="TickerQ.Dashboard" Version="9.0.0" />
185+
<PackageVersion Include="TickerQ.EntityFrameworkCore" Version="9.0.0" />
176186
</ItemGroup>
177187
<ItemGroup Condition=" '$(TargetFramework)' == 'net10.0' ">
178188
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="10.0.5" />
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
3+
var builder = DistributedApplication.CreateBuilder(args);
4+
5+
var username = builder.AddParameter("username", "guest", secret: true);
6+
var password = builder.AddParameter("password", "guest", secret: true);
7+
8+
var rabbitmq = builder.AddRabbitMQ("messaging", username, password)
9+
.WithManagementPlugin();
10+
11+
builder.AddProject<Projects.Greeting_Producer>("greeting-producer")
12+
13+
.WithReference(rabbitmq);
14+
15+
builder.AddProject<Projects.Greeting_Consumer>("greeting-consumer")
16+
.WithReference(rabbitmq);
17+
18+
builder.Build().Run();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<Sdk Name="Aspire.AppHost.Sdk" Version="9.5.0" />
4+
5+
<PropertyGroup>
6+
<OutputType>Exe</OutputType>
7+
<TargetFramework>net9.0</TargetFramework>
8+
<ImplicitUsings>enable</ImplicitUsings>
9+
<Nullable>enable</Nullable>
10+
<UserSecretsId>3a3c00ef-01a0-49f2-9ad2-dbb7edddd60a</UserSecretsId>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="Aspire.Hosting.AppHost" />
15+
<PackageReference Include="Aspire.Hosting.RabbitMQ" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="..\Greeting.Consumer\Greeting.Consumer.csproj" />
20+
<ProjectReference Include="..\Greeting.Producer\Greeting.Producer.csproj" />
21+
</ItemGroup>
22+
23+
24+
</Project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"https": {
5+
"commandName": "Project",
6+
"dotnetRunMessages": true,
7+
"launchBrowser": true,
8+
"applicationUrl": "https://localhost:17275;http://localhost:15245",
9+
"environmentVariables": {
10+
"ASPNETCORE_ENVIRONMENT": "Development",
11+
"DOTNET_ENVIRONMENT": "Development",
12+
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21117",
13+
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22259"
14+
}
15+
},
16+
"http": {
17+
"commandName": "Project",
18+
"dotnetRunMessages": true,
19+
"launchBrowser": true,
20+
"applicationUrl": "http://localhost:15245",
21+
"environmentVariables": {
22+
"ASPNETCORE_ENVIRONMENT": "Development",
23+
"DOTNET_ENVIRONMENT": "Development",
24+
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19117",
25+
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20156"
26+
}
27+
}
28+
}
29+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning",
6+
"Aspire.Hosting.Dcp": "Warning"
7+
}
8+
}
9+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\..\..\..\src\Paramore.Brighter.MessagingGateway.RMQ.Async\Paramore.Brighter.MessagingGateway.RMQ.Async.csproj" />
11+
<ProjectReference Include="..\..\..\..\src\Paramore.Brighter.ServiceActivator.Extensions.DependencyInjection\Paramore.Brighter.ServiceActivator.Extensions.DependencyInjection.csproj" />
12+
<ProjectReference Include="..\..\..\..\src\Paramore.Brighter.ServiceActivator.Extensions.Hosting\Paramore.Brighter.ServiceActivator.Extensions.Hosting.csproj" />
13+
<ProjectReference Include="..\..\..\..\src\Paramore.Brighter.ServiceActivator\Paramore.Brighter.ServiceActivator.csproj" />
14+
<ProjectReference Include="..\Greeting.Models\Greeting.Models.csproj" />
15+
<ProjectReference Include="..\Greeting.ServiceDefaults\Greeting.ServiceDefaults.csproj" />
16+
</ItemGroup>
17+
18+
</Project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Greeting.Models;
2+
using Paramore.Brighter;
3+
4+
namespace Greeting.Consumer
5+
{
6+
public class GreetingHandler : RequestHandlerAsync<GreetingEvent>
7+
{
8+
private readonly ILogger<GreetingHandler> _logger;
9+
10+
public GreetingHandler(ILogger<GreetingHandler> logger)
11+
{
12+
_logger = logger;
13+
}
14+
public override Task<GreetingEvent> HandleAsync(GreetingEvent command, CancellationToken cancellationToken = default)
15+
{
16+
_logger.LogInformation("Hello {Name}", command.Name);
17+
return base.HandleAsync(command, cancellationToken);
18+
}
19+
20+
}
21+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using Greeting.Consumer;
2+
using Greeting.Models;
3+
using Paramore.Brighter;
4+
using Paramore.Brighter.MessagingGateway.RMQ.Async;
5+
using Paramore.Brighter.ServiceActivator.Extensions.DependencyInjection;
6+
using Paramore.Brighter.ServiceActivator.Extensions.Hosting;
7+
8+
9+
var builder = WebApplication.CreateBuilder(args);
10+
11+
builder.AddServiceDefaults();
12+
var cnstring = builder.Configuration.GetConnectionString("messaging");
13+
var rmqConnection = new RmqMessagingGatewayConnection
14+
{
15+
AmpqUri = new AmqpUriSpecification(new Uri(cnstring)),
16+
Exchange = new Exchange("paramore.brighter.exchange"),
17+
};
18+
19+
// Register the existing handler(s)
20+
builder.Services.AddTransient(typeof(GreetingHandler));
21+
22+
23+
builder.Services.AddConsumers(opt =>
24+
{
25+
opt.Subscriptions = new Subscription[]
26+
{
27+
new RmqSubscription<GreetingEvent>(
28+
new SubscriptionName("paramore.example.greeting"),
29+
new ChannelName("greeting.event"),
30+
new RoutingKey("greeting.event"),
31+
makeChannels: OnMissingChannel.Create,
32+
messagePumpType: MessagePumpType.Proactor
33+
),
34+
};
35+
36+
opt.DefaultChannelFactory = new ChannelFactory(
37+
new RmqMessageConsumerFactory(rmqConnection)
38+
);
39+
40+
})
41+
.AutoFromAssemblies();
42+
43+
builder.Services
44+
.AddHostedService<ServiceActivatorHostedService>();
45+
46+
47+
var app = builder.Build();
48+
49+
app.MapDefaultEndpoints();
50+
51+
52+
app.UseHttpsRedirection();
53+
54+
app.MapGet("/", () =>
55+
{
56+
return "helloConsumer";
57+
});
58+
59+
app.Run();
60+
61+

0 commit comments

Comments
 (0)