Skip to content

Commit

Permalink
feat: add support for single file applications
Browse files Browse the repository at this point in the history
  • Loading branch information
prskr committed Jan 22, 2021
1 parent 2e7a0d5 commit 012f85f
Show file tree
Hide file tree
Showing 15 changed files with 671 additions and 21 deletions.
30 changes: 30 additions & 0 deletions Motor.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsumeAndMultiOutputPublis
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTelemetryExample", "examples\OpenTelemetryExample\OpenTelemetryExample.csproj", "{E7F2E446-E2F5-4AD9-8328-42F1B5B4E245}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Motor.Extensions.Hosting.Nano", "src\Motor.Extensions.Hosting.Nano\Motor.Extensions.Hosting.Nano.csproj", "{15711F68-D012-4727-A4D4-5738171E7831}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SingleFileMessagingService", "examples\SingleFileMessagingService\SingleFileMessagingService.csproj", "{DD34D143-DC96-426C-8D6E-8389DEC37390}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -586,6 +590,30 @@ Global
{E7F2E446-E2F5-4AD9-8328-42F1B5B4E245}.Release|x64.Build.0 = Release|Any CPU
{E7F2E446-E2F5-4AD9-8328-42F1B5B4E245}.Release|x86.ActiveCfg = Release|Any CPU
{E7F2E446-E2F5-4AD9-8328-42F1B5B4E245}.Release|x86.Build.0 = Release|Any CPU
{15711F68-D012-4727-A4D4-5738171E7831}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{15711F68-D012-4727-A4D4-5738171E7831}.Debug|Any CPU.Build.0 = Debug|Any CPU
{15711F68-D012-4727-A4D4-5738171E7831}.Debug|x64.ActiveCfg = Debug|Any CPU
{15711F68-D012-4727-A4D4-5738171E7831}.Debug|x64.Build.0 = Debug|Any CPU
{15711F68-D012-4727-A4D4-5738171E7831}.Debug|x86.ActiveCfg = Debug|Any CPU
{15711F68-D012-4727-A4D4-5738171E7831}.Debug|x86.Build.0 = Debug|Any CPU
{15711F68-D012-4727-A4D4-5738171E7831}.Release|Any CPU.ActiveCfg = Release|Any CPU
{15711F68-D012-4727-A4D4-5738171E7831}.Release|Any CPU.Build.0 = Release|Any CPU
{15711F68-D012-4727-A4D4-5738171E7831}.Release|x64.ActiveCfg = Release|Any CPU
{15711F68-D012-4727-A4D4-5738171E7831}.Release|x64.Build.0 = Release|Any CPU
{15711F68-D012-4727-A4D4-5738171E7831}.Release|x86.ActiveCfg = Release|Any CPU
{15711F68-D012-4727-A4D4-5738171E7831}.Release|x86.Build.0 = Release|Any CPU
{DD34D143-DC96-426C-8D6E-8389DEC37390}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DD34D143-DC96-426C-8D6E-8389DEC37390}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DD34D143-DC96-426C-8D6E-8389DEC37390}.Debug|x64.ActiveCfg = Debug|Any CPU
{DD34D143-DC96-426C-8D6E-8389DEC37390}.Debug|x64.Build.0 = Debug|Any CPU
{DD34D143-DC96-426C-8D6E-8389DEC37390}.Debug|x86.ActiveCfg = Debug|Any CPU
{DD34D143-DC96-426C-8D6E-8389DEC37390}.Debug|x86.Build.0 = Debug|Any CPU
{DD34D143-DC96-426C-8D6E-8389DEC37390}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DD34D143-DC96-426C-8D6E-8389DEC37390}.Release|Any CPU.Build.0 = Release|Any CPU
{DD34D143-DC96-426C-8D6E-8389DEC37390}.Release|x64.ActiveCfg = Release|Any CPU
{DD34D143-DC96-426C-8D6E-8389DEC37390}.Release|x64.Build.0 = Release|Any CPU
{DD34D143-DC96-426C-8D6E-8389DEC37390}.Release|x86.ActiveCfg = Release|Any CPU
{DD34D143-DC96-426C-8D6E-8389DEC37390}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -631,6 +659,8 @@ Global
{FA64170E-BF10-4670-84C6-1EF36E143E08} = {3DC7D216-6908-4759-B86F-759FDAE393D9}
{F8386DEA-8905-4157-B949-CC151F3FB8D2} = {3DC7D216-6908-4759-B86F-759FDAE393D9}
{E7F2E446-E2F5-4AD9-8328-42F1B5B4E245} = {3DC7D216-6908-4759-B86F-759FDAE393D9}
{15711F68-D012-4727-A4D4-5738171E7831} = {749B1421-3177-4C7A-A66B-541BD4E925B0}
{DD34D143-DC96-426C-8D6E-8389DEC37390} = {3DC7D216-6908-4759-B86F-759FDAE393D9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5E91C34C-3AEC-4084-BA02-753C9236AA34}
Expand Down
6 changes: 1 addition & 5 deletions examples/ConsumeAndPublishWithRabbitMQ/Model/InputMessage.cs
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);
}
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ private static OutputMessage MagicFunc(InputMessage input)
throw new ArgumentNullException("FancyText is empty");
}

var output = new OutputMessage
{
NotSoFancyText = input.FancyText.Reverse().ToString(),
NotSoFancyNumber = input.FancyNumber * -1,
};
var output = new OutputMessage(input.FancyText.Reverse().ToString(), input.FancyNumber * -1);
return output;
}
}
Expand Down
37 changes: 37 additions & 0 deletions examples/SingleFileMessagingService/Program.cs
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);
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>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static IMotorHostBuilder ConfigureSerilog(this IMotorHostBuilder hostBuil
.WriteTo.Console(new JsonFormatter(renderMessage: true));
configuration?.Invoke(hostingContext, loggerConfiguration);
})
.ConfigureServices((hostContext, services) =>
.ConfigureServices((_, services) =>
{
services.AddLogging(loggingBuilder => loggingBuilder.AddSerilog(dispose: true));
});
Expand Down
26 changes: 26 additions & 0 deletions src/Motor.Extensions.Hosting.Nano/AnonymousMultiOutputService.cs
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 src/Motor.Extensions.Hosting.Nano/AnonymousNoOutputService.cs
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 src/Motor.Extensions.Hosting.Nano/AnonymousSingleOutputService.cs
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);
}
}
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>
Loading

0 comments on commit 012f85f

Please sign in to comment.