-
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 #131 Signed-off-by: jan.jansen <[email protected]>
- Loading branch information
Showing
12 changed files
with
240 additions
and
1 deletion.
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,9 @@ | ||
namespace Motor.Extensions.Hosting.Bridge | ||
{ | ||
public enum BridgeConsumerType | ||
{ | ||
RabbitMQ, | ||
Kafka, | ||
SQS | ||
} | ||
} |
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 Motor.Extensions.Hosting.Bridge | ||
{ | ||
public enum BridgePublisherType | ||
{ | ||
RabbitMQ, | ||
Kafka | ||
} | ||
} |
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,16 @@ | ||
FROM mcr.microsoft.com/dotnet/aspnet:5.0-alpine | ||
COPY . /data | ||
WORKDIR /data | ||
|
||
ARG DOTNET_ENVIRONMENT | ||
ENV DOTNET_ENVIRONMENT=$DOTNET_ENVIRONMENT | ||
|
||
HEALTHCHECK CMD wget --quiet --tries=1 --spider http://localhost:9110/health || exit 1 | ||
|
||
ENTRYPOINT dotnet /data/Motor.Extensions.Hosting.Bridge.dll | ||
|
||
LABEL org.opencontainers.image.title="Motor.NET Bridge Docker Image" \ | ||
org.opencontainers.image.description="Motor.NET" \ | ||
org.opencontainers.image.url="https://github.com/GDATASoftwareAG/motornet" \ | ||
org.opencontainers.image.source="https://github.com/GDATASoftwareAG/motornet/tree/master/src/Motor.Extensions.Hosting.Bridge/" \ | ||
org.opencontainers.image.license="MIT" |
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,4 @@ | ||
namespace Motor.Extensions.Hosting.Bridge.Internals | ||
{ | ||
public record ByteData(byte[] data); | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Motor.Extensions.Hosting.Bridge/Internals/ByteDataConversions.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,22 @@ | ||
using System; | ||
using Motor.Extensions.Conversion.Abstractions; | ||
|
||
namespace Motor.Extensions.Hosting.Bridge.Internals | ||
{ | ||
public class ByteDataConversions : IMessageDeserializer<ByteData>, IMessageSerializer<ByteData> | ||
{ | ||
public ByteData Deserialize(byte[] message) | ||
{ | ||
if (message is null || message.Length == 0) | ||
{ | ||
throw new ArgumentNullException(nameof(message)); | ||
} | ||
return new ByteData(message); | ||
} | ||
|
||
public byte[] Serialize(ByteData message) | ||
{ | ||
return message.data; | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Motor.Extensions.Hosting.Bridge/Internals/PassThoughService.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.Threading; | ||
using System.Threading.Tasks; | ||
using Motor.Extensions.Diagnostics.Metrics.Abstractions; | ||
using Motor.Extensions.Hosting.Abstractions; | ||
using Prometheus.Client; | ||
|
||
namespace Motor.Extensions.Hosting.Bridge.Internals | ||
{ | ||
public class PassThoughService : ISingleOutputService<ByteData, ByteData> | ||
{ | ||
private readonly ISummary summary; | ||
|
||
public PassThoughService(IMetricsFactory<PassThoughService> metricsFactory) | ||
{ | ||
summary = metricsFactory.CreateSummary("message_pass_tough_bytes", ""); | ||
} | ||
|
||
public Task<MotorCloudEvent<ByteData>?> ConvertMessageAsync(MotorCloudEvent<ByteData> dataCloudEvent, | ||
CancellationToken token = default) | ||
{ | ||
summary.Observe(dataCloudEvent.TypedData.data.Length); | ||
return Task.FromResult<MotorCloudEvent<ByteData>?>(dataCloudEvent.CreateNew(dataCloudEvent.TypedData)); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/Motor.Extensions.Hosting.Bridge/Motor.Extensions.Hosting.Bridge.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,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Motor.Extensions.Conversion.Abstractions\Motor.Extensions.Conversion.Abstractions.csproj" /> | ||
<ProjectReference Include="..\Motor.Extensions.Hosting.Kafka\Motor.Extensions.Hosting.Kafka.csproj" /> | ||
<ProjectReference Include="..\Motor.Extensions.Hosting.RabbitMQ\Motor.Extensions.Hosting.RabbitMQ.csproj" /> | ||
<ProjectReference Include="..\Motor.Extensions.Hosting.SQS\Motor.Extensions.Hosting.SQS.csproj" /> | ||
<ProjectReference Include="..\Motor.Extensions.Utilities\Motor.Extensions.Utilities.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="Dockerfile"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="appsettings.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
<Import Project="$(MSBuildThisFileDirectory)../../shared.csproj" /> | ||
|
||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Motor.Extensions.Hosting.Abstractions; | ||
using Motor.Extensions.Hosting.Bridge; | ||
using Motor.Extensions.Hosting.Bridge.Internals; | ||
using Motor.Extensions.Hosting.Consumer; | ||
using Motor.Extensions.Hosting.Kafka; | ||
using Motor.Extensions.Hosting.Publisher; | ||
using Motor.Extensions.Hosting.RabbitMQ; | ||
using Motor.Extensions.Hosting.SQS; | ||
using Motor.Extensions.Utilities; | ||
|
||
|
||
await MotorHost.CreateDefaultBuilder() | ||
.ConfigureSingleOutputService<ByteData, ByteData>() | ||
.ConfigureServices((_, collection) => | ||
{ | ||
collection.AddTransient<ISingleOutputService<ByteData, ByteData>, PassThoughService>(); | ||
}) | ||
.ConfigurePublisher<ByteData>((ctx, builder) => | ||
{ | ||
var s = ctx.Configuration["PublisherType"]; | ||
var publisherType = Enum.Parse<BridgePublisherType>(s, true); | ||
switch (publisherType) | ||
{ | ||
case BridgePublisherType.RabbitMQ: | ||
builder.AddRabbitMQ("Publisher"); | ||
break; | ||
case BridgePublisherType.Kafka: | ||
builder.AddKafka("Publisher"); | ||
break; | ||
default: | ||
throw new ArgumentOutOfRangeException(); | ||
} | ||
|
||
builder.AddSerializer<ByteDataConversions>(); | ||
}) | ||
.ConfigureConsumer<ByteData>((ctx, builder) => | ||
{ | ||
var s = ctx.Configuration["ConsumerType"]; | ||
var consumerType = Enum.Parse<BridgeConsumerType>(s, true); | ||
switch (consumerType) | ||
{ | ||
case BridgeConsumerType.RabbitMQ: | ||
builder.AddRabbitMQ("Consumer"); | ||
break; | ||
case BridgeConsumerType.Kafka: | ||
builder.AddKafka("Consumer"); | ||
break; | ||
case BridgeConsumerType.SQS: | ||
builder.AddSQS("Consumer"); | ||
break; | ||
default: | ||
throw new ArgumentOutOfRangeException(); | ||
} | ||
|
||
builder.AddDeserializer<ByteDataConversions>(); | ||
}) | ||
.RunConsoleAsync(); |
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,6 @@ | ||
{ | ||
"ConsumerType": "RabbitMQ", | ||
"Consumer": {}, | ||
"PublisherType": "RabbitMQ", | ||
"Publisher": {} | ||
} |