-
Notifications
You must be signed in to change notification settings - Fork 283
Add sample for tickerQ #4038
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AboubakrNasef
wants to merge
4
commits into
BrighterCommand:master
Choose a base branch
from
AboubakrNasef:AddSampleForTickerQ
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add sample for tickerQ #4038
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| using Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| var builder = DistributedApplication.CreateBuilder(args); | ||
|
|
||
| var username = builder.AddParameter("username", "guest", secret: true); | ||
| var password = builder.AddParameter("password", "guest", secret: true); | ||
|
|
||
| var rabbitmq = builder.AddRabbitMQ("messaging", username, password) | ||
| .WithManagementPlugin(); | ||
|
|
||
| builder.AddProject<Projects.Greeting_Producer>("greeting-producer") | ||
|
|
||
| .WithReference(rabbitmq); | ||
|
|
||
| builder.AddProject<Projects.Greeting_Consumer>("greeting-consumer") | ||
| .WithReference(rabbitmq); | ||
|
|
||
| builder.Build().Run(); |
24 changes: 24 additions & 0 deletions
24
samples/Scheduler/TickerQ/Greeting.AppHost/Greeting.AppHost.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <Sdk Name="Aspire.AppHost.Sdk" Version="9.5.0" /> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net9.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <UserSecretsId>3a3c00ef-01a0-49f2-9ad2-dbb7edddd60a</UserSecretsId> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Aspire.Hosting.AppHost" /> | ||
| <PackageReference Include="Aspire.Hosting.RabbitMQ" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Greeting.Consumer\Greeting.Consumer.csproj" /> | ||
| <ProjectReference Include="..\Greeting.Producer\Greeting.Producer.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
|
|
||
| </Project> |
29 changes: 29 additions & 0 deletions
29
samples/Scheduler/TickerQ/Greeting.AppHost/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/launchsettings.json", | ||
| "profiles": { | ||
| "https": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "https://localhost:17275;http://localhost:15245", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21117", | ||
| "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22259" | ||
| } | ||
| }, | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "http://localhost:15245", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19117", | ||
| "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20156" | ||
| } | ||
| } | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
samples/Scheduler/TickerQ/Greeting.AppHost/appsettings.Development.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning", | ||
| "Aspire.Hosting.Dcp": "Warning" | ||
| } | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
samples/Scheduler/TickerQ/Greeting.Consumer/Greeting.Consumer.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net9.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\..\..\src\Paramore.Brighter.MessagingGateway.RMQ.Async\Paramore.Brighter.MessagingGateway.RMQ.Async.csproj" /> | ||
| <ProjectReference Include="..\..\..\..\src\Paramore.Brighter.ServiceActivator.Extensions.DependencyInjection\Paramore.Brighter.ServiceActivator.Extensions.DependencyInjection.csproj" /> | ||
| <ProjectReference Include="..\..\..\..\src\Paramore.Brighter.ServiceActivator.Extensions.Hosting\Paramore.Brighter.ServiceActivator.Extensions.Hosting.csproj" /> | ||
| <ProjectReference Include="..\..\..\..\src\Paramore.Brighter.ServiceActivator\Paramore.Brighter.ServiceActivator.csproj" /> | ||
| <ProjectReference Include="..\Greeting.Models\Greeting.Models.csproj" /> | ||
| <ProjectReference Include="..\Greeting.ServiceDefaults\Greeting.ServiceDefaults.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
21 changes: 21 additions & 0 deletions
21
samples/Scheduler/TickerQ/Greeting.Consumer/GreetingHandler.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| using Greeting.Models; | ||
| using Paramore.Brighter; | ||
|
|
||
| namespace Greeting.Consumer | ||
| { | ||
| public class GreetingHandler : RequestHandlerAsync<GreetingEvent> | ||
| { | ||
| private readonly ILogger<GreetingHandler> _logger; | ||
|
|
||
| public GreetingHandler(ILogger<GreetingHandler> logger) | ||
| { | ||
| _logger = logger; | ||
| } | ||
| public override Task<GreetingEvent> HandleAsync(GreetingEvent command, CancellationToken cancellationToken = default) | ||
| { | ||
| _logger.LogInformation("Hello {Name}", command.Name); | ||
| return base.HandleAsync(command, cancellationToken); | ||
| } | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| using Greeting.Consumer; | ||
| using Greeting.Models; | ||
| using Paramore.Brighter; | ||
| using Paramore.Brighter.MessagingGateway.RMQ.Async; | ||
| using Paramore.Brighter.ServiceActivator.Extensions.DependencyInjection; | ||
| using Paramore.Brighter.ServiceActivator.Extensions.Hosting; | ||
|
|
||
|
|
||
| var builder = WebApplication.CreateBuilder(args); | ||
|
|
||
| builder.AddServiceDefaults(); | ||
| var cnstring = builder.Configuration.GetConnectionString("messaging"); | ||
| var rmqConnection = new RmqMessagingGatewayConnection | ||
| { | ||
| AmpqUri = new AmqpUriSpecification(new Uri(cnstring)), | ||
| Exchange = new Exchange("paramore.brighter.exchange"), | ||
| }; | ||
|
|
||
| // Register the existing handler(s) | ||
| builder.Services.AddTransient(typeof(GreetingHandler)); | ||
|
|
||
|
|
||
| builder.Services.AddConsumers(opt => | ||
| { | ||
| opt.Subscriptions = new Subscription[] | ||
| { | ||
| new RmqSubscription<GreetingEvent>( | ||
| new SubscriptionName("paramore.example.greeting"), | ||
| new ChannelName("greeting.event"), | ||
| new RoutingKey("greeting.event"), | ||
| makeChannels: OnMissingChannel.Create, | ||
| messagePumpType: MessagePumpType.Proactor | ||
| ), | ||
| }; | ||
|
|
||
| opt.DefaultChannelFactory = new ChannelFactory( | ||
| new RmqMessageConsumerFactory(rmqConnection) | ||
| ); | ||
|
|
||
| }) | ||
| .AutoFromAssemblies(); | ||
|
|
||
| builder.Services | ||
| .AddHostedService<ServiceActivatorHostedService>(); | ||
|
|
||
|
|
||
| var app = builder.Build(); | ||
|
|
||
| app.MapDefaultEndpoints(); | ||
|
|
||
|
|
||
| app.UseHttpsRedirection(); | ||
|
|
||
| app.MapGet("/", () => | ||
| { | ||
| return "helloConsumer"; | ||
| }); | ||
|
|
||
| app.Run(); | ||
|
|
||
|
|
23 changes: 23 additions & 0 deletions
23
samples/Scheduler/TickerQ/Greeting.Consumer/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/launchsettings.json", | ||
| "profiles": { | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": false, | ||
| "applicationUrl": "http://localhost:5237", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| }, | ||
| "https": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": false, | ||
| "applicationUrl": "https://localhost:7122;http://localhost:5237", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| } | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
samples/Scheduler/TickerQ/Greeting.Consumer/TickerQ.Consumer.http
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| @TickerQ.Consumer_HostAddress = http://localhost:5237 | ||
|
|
||
| GET {{TickerQ.Consumer_HostAddress}}/weatherforecast/ | ||
| Accept: application/json | ||
|
|
||
| ### |
8 changes: 8 additions & 0 deletions
8
samples/Scheduler/TickerQ/Greeting.Consumer/appsettings.Development.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| }, | ||
| "AllowedHosts": "*" | ||
| } |
14 changes: 14 additions & 0 deletions
14
samples/Scheduler/TickerQ/Greeting.Models/Greeting.Models.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net9.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\..\..\src\Paramore.Brighter.MessagingGateway.RMQ.Async\Paramore.Brighter.MessagingGateway.RMQ.Async.csproj" /> | ||
| <ProjectReference Include="..\..\..\..\src\Paramore.Brighter\Paramore.Brighter.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
16 changes: 16 additions & 0 deletions
16
samples/Scheduler/TickerQ/Greeting.Models/GreetingEvent.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| using Paramore.Brighter; | ||
|
|
||
| namespace Greeting.Models | ||
| { | ||
| public class GreetingEvent : Event | ||
| { | ||
| public GreetingEvent() : base(Id.Random()) { } | ||
|
|
||
| public GreetingEvent(string name) : base(Id.Random()) | ||
| { | ||
| Name = name; | ||
| } | ||
|
|
||
| public string Name { get; set; } = string.Empty; | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
samples/Scheduler/TickerQ/Greeting.Models/GreetingMapper.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| using System.Text.Json; | ||
| using Paramore.Brighter; | ||
| using Paramore.Brighter.JsonConverters; | ||
|
|
||
| namespace Greeting.Models | ||
| { | ||
| public class GreetingMapper : IAmAMessageMapper<GreetingEvent> | ||
| { | ||
| public IRequestContext? Context { get; set; } | ||
| public GreetingMapper() | ||
| { | ||
|
|
||
| } | ||
| public Message MapToMessage(GreetingEvent request, Publication publication) | ||
| { | ||
| var header = new MessageHeader(messageId: request.Id, topic: publication.Topic, messageType: MessageType.MT_EVENT); | ||
| var body = new MessageBody(JsonSerializer.Serialize(request, JsonSerialisationOptions.Options)); | ||
| var message = new Message(header, body); | ||
| return message; | ||
| } | ||
|
|
||
| public GreetingEvent MapToRequest(Message message) | ||
| { | ||
| return JsonSerializer.Deserialize<GreetingEvent>(message.Body.Bytes)!; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just use a default mapper now, and I am slowly trying to move our samples over, except for the ones that demonstrate explicit mapping, or transformer pipelines