-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #8 Part of #9 * Add NuGet.config allow `dotnet tool restore`. * Add example for a MultiOutputService * Add example for a OpenTelemetry Signed-off-by: jan.jansen <[email protected]>
- Loading branch information
Showing
30 changed files
with
512 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<packageSources> | ||
<clear /> | ||
<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" /> | ||
<add key="dotnet5" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json" /> | ||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" /> | ||
</packageSources> | ||
<disabledPackageSources /> | ||
</configuration> |
This file contains 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
24 changes: 24 additions & 0 deletions
24
...sumeAndMultiOutputPublisherWithRabbitMQ/ConsumeAndMultiOutputPublisherWithRabbitMQ.csproj
This file contains 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.Web"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<Product>Motor.NET</Product> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Motor.Extensions.Conversion.SystemJson\Motor.Extensions.Conversion.SystemJson.csproj" /> | ||
<ProjectReference Include="..\..\src\Motor.Extensions.Hosting.RabbitMQ\Motor.Extensions.Hosting.RabbitMQ.csproj" /> | ||
<ProjectReference Include="..\..\src\Motor.Extensions.Utilities\Motor.Extensions.Utilities.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="appsettings.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="appsettings.Production.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
8 changes: 8 additions & 0 deletions
8
examples/ConsumeAndMultiOutputPublisherWithRabbitMQ/Model/InputMessage.cs
This file contains 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 @@ | ||
namespace ConsumeAndMultiOutputPublisherWithRabbitMQ.Model | ||
{ | ||
public record InputMessage | ||
{ | ||
public string FancyText { get; set; } = "FooBar"; | ||
public int FancyNumber { get; set; } = 42; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
examples/ConsumeAndMultiOutputPublisherWithRabbitMQ/Model/OutputMessage.cs
This file contains 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 @@ | ||
namespace ConsumeAndMultiOutputPublisherWithRabbitMQ.Model | ||
{ | ||
public record OutputMessage | ||
{ | ||
public string NotSoFancyText { get; set; } | ||
public int NotSoFancyNumber { get; set; } | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
examples/ConsumeAndMultiOutputPublisherWithRabbitMQ/MultiOutputService.cs
This file contains 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,52 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using ConsumeAndMultiOutputPublisherWithRabbitMQ.Model; | ||
using Motor.Extensions.Hosting.Abstractions; | ||
|
||
namespace ConsumeAndMultiOutputPublisherWithRabbitMQ | ||
{ | ||
public class MultiOutputService : IMultiOutputService<InputMessage, OutputMessage> | ||
{ | ||
// Handle incoming messages | ||
public Task<IEnumerable<MotorCloudEvent<OutputMessage>>> ConvertMessageAsync( | ||
MotorCloudEvent<InputMessage> inputEvent, | ||
CancellationToken token = default) | ||
{ | ||
// Get the input message from the cloud event | ||
var input = inputEvent.TypedData; | ||
|
||
// Do your magic here ..... | ||
var output = MagicFunc(input); | ||
|
||
// Create a new cloud event from your output message which is automatically published and return a new task. | ||
var outputEvent = output.Select(singleEvent => inputEvent.CreateNew(singleEvent)); | ||
return Task.FromResult(outputEvent); | ||
} | ||
|
||
private static IEnumerable<OutputMessage> MagicFunc(InputMessage input) | ||
{ | ||
if (string.IsNullOrEmpty(input.FancyText)) | ||
{ | ||
// Reject message in RabbitMQ queue (Any ArgumentException can be used to reject to messages.). | ||
throw new ArgumentNullException("FancyText is empty"); | ||
} | ||
|
||
return new List<OutputMessage> | ||
{ | ||
new() | ||
{ | ||
NotSoFancyText = input.FancyText.Reverse().ToString(), | ||
NotSoFancyNumber = input.FancyNumber * -1, | ||
}, | ||
new() | ||
{ | ||
NotSoFancyText = input.FancyText, | ||
NotSoFancyNumber = input.FancyNumber * -2, | ||
}, | ||
}; | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
examples/ConsumeAndMultiOutputPublisherWithRabbitMQ/Program.cs
This file contains 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,37 @@ | ||
using ConsumeAndMultiOutputPublisherWithRabbitMQ; | ||
using ConsumeAndMultiOutputPublisherWithRabbitMQ.Model; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Motor.Extensions.Conversion.SystemJson; | ||
using Motor.Extensions.Hosting.Abstractions; | ||
using Motor.Extensions.Hosting.Consumer; | ||
using Motor.Extensions.Hosting.Publisher; | ||
using Motor.Extensions.Hosting.RabbitMQ; | ||
using Motor.Extensions.Utilities; | ||
|
||
await MotorHost.CreateDefaultBuilder() | ||
// Configure the types of the input and output messages | ||
.ConfigureMultiOutputService<InputMessage, OutputMessage>() | ||
.ConfigureServices((_, services) => | ||
{ | ||
// Add a handler for the input message which returns an output message | ||
// This handler is called for every new incoming message | ||
services.AddTransient<IMultiOutputService<InputMessage, OutputMessage>, MultiOutputService>(); | ||
}) | ||
// Add the incomming communication module. | ||
.ConfigureConsumer<InputMessage>((_, builder) => | ||
{ | ||
// In this case the messages are received from RabbitMQ | ||
builder.AddRabbitMQ(); | ||
// The encoding of the incoming message, such that the handler is able to deserialize the message | ||
builder.AddSystemJson(); | ||
}) | ||
// Add the outgoing communication module. | ||
.ConfigurePublisher<OutputMessage>((_, builder) => | ||
{ | ||
// In this case the messages are send to RabbitMQ | ||
builder.AddRabbitMQ(); | ||
// The encoding of the outgoing message, such that the handler is able to serialize the message | ||
builder.AddSystemJson(); | ||
}) | ||
.RunConsoleAsync(); |
27 changes: 27 additions & 0 deletions
27
examples/ConsumeAndMultiOutputPublisherWithRabbitMQ/Properties/launchSettings.json
This file contains 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 @@ | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:58904/", | ||
"sslPort": 44350 | ||
} | ||
}, | ||
"profiles": { | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"ConsumeAndPublishWithRabbitMQ": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "https://localhost:5001;http://localhost:5000" | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
examples/ConsumeAndMultiOutputPublisherWithRabbitMQ/appsettings.Production.json
This file contains 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,17 @@ | ||
{ | ||
"Serilog": { | ||
"MinimumLevel": { | ||
"Default": "Information" | ||
} | ||
}, | ||
"RabbitMQConsumer": { | ||
"Queue": { | ||
"Name": "ExampleProductionQueue" | ||
} | ||
}, | ||
"RabbitMQPublisher": { | ||
"PublishingTarget": { | ||
"RoutingKey": "production" | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
examples/ConsumeAndMultiOutputPublisherWithRabbitMQ/appsettings.json
This file contains 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,38 @@ | ||
{ | ||
"Serilog": { | ||
"MinimumLevel": { | ||
"Default": "Debug", | ||
"Override": { | ||
"Microsoft": "Warning", | ||
"Microsoft.Hosting.Lifetime": "Information", | ||
"System": "Warning" | ||
} | ||
} | ||
}, | ||
"RabbitMQConsumer": { | ||
"Host": "localhost", | ||
"VirtualHost": "/", | ||
"User": "guest", | ||
"Password": "guest", | ||
"Queue": { | ||
"Name": "ExampleQueue", | ||
"Bindings": [ | ||
{ | ||
"Exchange": "amq.topic", | ||
"RoutingKey": "input" | ||
} | ||
] | ||
}, | ||
"PrefetchCount": 10 | ||
}, | ||
"RabbitMQPublisher": { | ||
"Host": "localhost", | ||
"VirtualHost": "/", | ||
"User": "guest", | ||
"Password": "guest", | ||
"PublishingTarget": { | ||
"Exchange": "amq.topic", | ||
"RoutingKey": "ouput" | ||
} | ||
} | ||
} |
This file contains 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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
examples/Metrics/Model/InputMessage.cs → ...ples/MetricsExample/Model/InputMessage.cs
This file contains 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace Metrics.Model | ||
namespace MetricsExample.Model | ||
{ | ||
public record InputMessage | ||
{ | ||
|
6 changes: 3 additions & 3 deletions
6
examples/Metrics/Program.cs → examples/MetricsExample/Program.cs
This file contains 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
File renamed without changes.
This file contains 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
File renamed without changes.
File renamed without changes.
This file contains 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 @@ | ||
namespace OpenTelemetryExample.Model | ||
{ | ||
public record InputMessage | ||
{ | ||
public string FancyText { get; set; } = "FooBar"; | ||
public int FancyNumber { get; set; } = 42; | ||
} | ||
} |
This file contains 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 @@ | ||
namespace OpenTelemetryExample.Model | ||
{ | ||
public record OutputMessage | ||
{ | ||
public string NotSoFancyText { get; set; } | ||
public int NotSoFancyNumber { get; set; } | ||
} | ||
} |
Oops, something went wrong.