-
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.
feat: add support for single file applications
- Loading branch information
Showing
15 changed files
with
671 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,4 @@ | ||
namespace ConsumeAndPublishWithRabbitMQ.Model | ||
{ | ||
public record InputMessage | ||
{ | ||
public string FancyText { get; set; } = "FooBar"; | ||
public int FancyNumber { get; set; } = 42; | ||
} | ||
public record InputMessage(string FancyText = "FooBar", int FancyNumber = 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 |
---|---|---|
@@ -1,8 +1,4 @@ | ||
namespace ConsumeAndPublishWithRabbitMQ.Model | ||
{ | ||
public record OutputMessage | ||
{ | ||
public string NotSoFancyText { get; set; } | ||
public int NotSoFancyNumber { get; set; } | ||
} | ||
public record OutputMessage(string NotSoFancyText, int NotSoFancyNumber); | ||
} |
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,37 @@ | ||
using System; | ||
using System.Linq; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using Motor.Extensions.Conversion.SystemJson; | ||
using Motor.Extensions.Hosting.Consumer; | ||
using Motor.Extensions.Hosting.Nano; | ||
using Motor.Extensions.Hosting.Publisher; | ||
using Motor.Extensions.Hosting.RabbitMQ; | ||
using Motor.Extensions.Utilities; | ||
|
||
await MotorHost.CreateDefaultBuilder() | ||
.ConfigureAnonymousSingleOutputService<InputMessage, OutputMessage, ILogger>((cloudEvent, logger) => | ||
{ | ||
logger.LogInformation("Handling message - synchronously"); | ||
var data = cloudEvent.TypedData; | ||
return data switch | ||
{ | ||
{ FancyText: { Length: > 0 } } => cloudEvent.CreateNew(new OutputMessage(data.FancyText.Reverse().ToString(), | ||
data.FancyNumber * -1)), | ||
_ => throw new ArgumentNullException("FancyText is empty") | ||
}; | ||
}) | ||
.ConfigureConsumer<InputMessage>((_, builder) => | ||
{ | ||
builder.AddRabbitMQ(); | ||
builder.AddSystemJson(); | ||
}).ConfigurePublisher<OutputMessage>((_, builder) => | ||
{ | ||
builder.AddRabbitMQ(); | ||
builder.AddSystemJson(); | ||
}) | ||
.RunConsoleAsync(); | ||
|
||
public record OutputMessage(string NotSoFancyText, int NotSoFancyNumber); | ||
|
||
public record InputMessage(string FancyText = "FooBar", int FancyNumber = 42); |
15 changes: 15 additions & 0 deletions
15
examples/SingleFileMessagingService/SingleFileMessagingService.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,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net5.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Motor.Extensions.Conversion.SystemJson\Motor.Extensions.Conversion.SystemJson.csproj" /> | ||
<ProjectReference Include="..\..\src\Motor.Extensions.Hosting.Nano\Motor.Extensions.Hosting.Nano.csproj" /> | ||
<ProjectReference Include="..\..\src\Motor.Extensions.Hosting.RabbitMQ\Motor.Extensions.Hosting.RabbitMQ.csproj" /> | ||
<ProjectReference Include="..\..\src\Motor.Extensions.Utilities\Motor.Extensions.Utilities.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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
26 changes: 26 additions & 0 deletions
26
src/Motor.Extensions.Hosting.Nano/AnonymousMultiOutputService.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,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Motor.Extensions.Hosting.Abstractions; | ||
|
||
namespace Motor.Extensions.Hosting.Nano | ||
{ | ||
public class AnonymousMultiOutputService<TInput, TOutput> : IMultiOutputService<TInput, TOutput> where TInput : class where TOutput : class | ||
{ | ||
private readonly Func<MotorCloudEvent<TInput>, CancellationToken, Task<IEnumerable<MotorCloudEvent<TOutput>>>> _handler; | ||
|
||
public AnonymousMultiOutputService(Func<MotorCloudEvent<TInput>, CancellationToken, Task<IEnumerable<MotorCloudEvent<TOutput>>>> handler) | ||
{ | ||
_handler = handler; | ||
} | ||
|
||
public AnonymousMultiOutputService(Func<MotorCloudEvent<TInput>, IEnumerable<MotorCloudEvent<TOutput>>> handler) | ||
{ | ||
_handler = (cloudEvent, _) => Task.FromResult(handler(cloudEvent)); | ||
} | ||
|
||
public Task<IEnumerable<MotorCloudEvent<TOutput>>> ConvertMessageAsync(MotorCloudEvent<TInput> dataCloudEvent, | ||
CancellationToken token = default) => _handler(dataCloudEvent, token); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Motor.Extensions.Hosting.Nano/AnonymousNoOutputService.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,25 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Motor.Extensions.Hosting.Abstractions; | ||
|
||
namespace Motor.Extensions.Hosting.Nano | ||
{ | ||
public class AnonymousNoOutputService<TInput> : INoOutputService<TInput> where TInput : class | ||
{ | ||
private readonly Func<MotorCloudEvent<TInput>, CancellationToken, Task<ProcessedMessageStatus>> _handler; | ||
|
||
public AnonymousNoOutputService(Func<MotorCloudEvent<TInput>, CancellationToken, Task<ProcessedMessageStatus>> handler) | ||
{ | ||
_handler = handler; | ||
} | ||
|
||
public AnonymousNoOutputService(Func<MotorCloudEvent<TInput>, ProcessedMessageStatus> handler) | ||
{ | ||
_handler = (cloudEvent, _) => Task.FromResult(handler(cloudEvent)); | ||
} | ||
|
||
public Task<ProcessedMessageStatus> HandleMessageAsync(MotorCloudEvent<TInput> dataCloudEvent, | ||
CancellationToken token = default) => _handler(dataCloudEvent, token); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Motor.Extensions.Hosting.Nano/AnonymousSingleOutputService.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,25 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Motor.Extensions.Hosting.Abstractions; | ||
|
||
namespace Motor.Extensions.Hosting.Nano | ||
{ | ||
public class AnonymousSingleOutputService<TInput, TOutput> : ISingleOutputService<TInput, TOutput> where TInput : class where TOutput : class | ||
{ | ||
private readonly Func<MotorCloudEvent<TInput>, CancellationToken, Task<MotorCloudEvent<TOutput>>> _handler; | ||
|
||
public AnonymousSingleOutputService(Func<MotorCloudEvent<TInput>, CancellationToken, Task<MotorCloudEvent<TOutput>>> handler) | ||
{ | ||
_handler = handler; | ||
} | ||
|
||
public AnonymousSingleOutputService(Func<MotorCloudEvent<TInput>, MotorCloudEvent<TOutput>> handler) | ||
{ | ||
_handler = (cloudEvent, _) => Task.FromResult(handler(cloudEvent)); | ||
} | ||
|
||
public Task<MotorCloudEvent<TOutput>> ConvertMessageAsync(MotorCloudEvent<TInput> dataCloudEvent, | ||
CancellationToken token = default) => _handler(dataCloudEvent, token); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Motor.Extensions.Hosting.Nano/Motor.Extensions.Hosting.Nano.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,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Motor.Extensions.Hosting.Abstractions\Motor.Extensions.Hosting.Abstractions.csproj" /> | ||
<ProjectReference Include="..\Motor.Extensions.Utilities.Abstractions\Motor.Extensions.Utilities.Abstractions.csproj" /> | ||
<ProjectReference Include="..\Motor.Extensions.Utilities\Motor.Extensions.Utilities.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" /> | ||
</ItemGroup> | ||
|
||
<Import Project="$(MSBuildThisFileDirectory)../../shared.csproj" /> | ||
|
||
</Project> |
Oops, something went wrong.