![]() |
VOOZH | about |
dotnet add package Ninja.Sharp.OpenMessagingWrapper --version 0.0.3-alpha
NuGet\Install-Package Ninja.Sharp.OpenMessagingWrapper -Version 0.0.3-alpha
<PackageReference Include="Ninja.Sharp.OpenMessagingWrapper" Version="0.0.3-alpha" />
<PackageVersion Include="Ninja.Sharp.OpenMessagingWrapper" Version="0.0.3-alpha" />Directory.Packages.props
<PackageReference Include="Ninja.Sharp.OpenMessagingWrapper" />Project file
paket add Ninja.Sharp.OpenMessagingWrapper --version 0.0.3-alpha
#r "nuget: Ninja.Sharp.OpenMessagingWrapper, 0.0.3-alpha"
#:package Ninja.Sharp.OpenMessagingWrapper@0.0.3-alpha
#addin nuget:?package=Ninja.Sharp.OpenMessagingWrapper&version=0.0.3-alpha&prereleaseInstall as a Cake Addin
#tool nuget:?package=Ninja.Sharp.OpenMessagingWrapper&version=0.0.3-alpha&prereleaseInstall as a Cake Tool
👁 License: MIT
👁 issues - Ninja.Sharp.OpenMessagingWrapper
👁 stars - Ninja.Sharp.OpenMessagingWrapper
First release has been created!
| Package | NuGet Stable |
|---|---|
| OpenMessagingWrapper | 👁 OpenMessagingWrapper |
OpenMessagingWrapperWrapper is a NuGet .NET library that aims in simplifying usage for the most common messaging framework. The library encapsulates some behavior and common options for most frameworks, providing a simple management to rule them all via configuration.
Right now, it allows integration with these framework:
We'll try to provide abstraction for most popular message brokers, such as
OpenMessagingWrapperWrapper allows to use in the same application several message brokers at a time. However
OpenMessagingWrapperWrapper can be configured manually or via appsettings.json. Configuration differs for each message broker, while the subsequent usage will be hidden by OpenMessagingWrapperWrapper framework. If you're using appsetting.json, then you just need to add configurations under the 'Messaging' tag:
{
"Messaging": {
"Kafka": {
"Identifier": "myIdentifier",
"BootstrapServers": [
{
"Host": "myHost",
"Port": 9092
}
],
"SecurityProtocol": "SaslSsl",
"UserName": "myUsername",
"Password": "myPassword",
"GroupId": "myGroupId",
"SaslMechanism": "ScramSha256"
},
"Artemis": {
"Identifier": "myIdentifier",
"Retries": 2,
"RetryWaitTime": 500,
"Endpoints": [
{
"Host": "myHost",
"Port": 61616,
"Username": "myUsername",
"Password": "myUsername",
}
]
},
}
}
otherwise, if you're using manual configuration, you just need to add configurations when you add the requested services
builder.Services.AddArtemisServices(new ArtemisConfig()
{
//...
});
OpenMessagingWrapperWrapper manages allows you to add several message brokers, and simplify the message management. You just need to provide, for each message broker you are configuring
builder.Services
.AddArtemisServices(builder.Configuration)
.AddProducer("myArtemisProducerTopic")
.AddConsumer<LoggerMqConsumer>("myArtemisConsumerTopic")
.Build();
builder.Services
.AddKafkaServices(builder.Configuration)
.AddProducer("myKafkaProducerTopic1")
.AddProducer("myKafkaProducerTopic2")
.AddProducer("myKafkaProducerTopic3")
.AddConsumer<LoggerMqConsumer>("myKafkaConsumerTopic1")
.AddConsumer<LoggerMqConsumer>("myKafkaConsumerTopic2")
.Build();
Once configured, sending a message is quite easy. You do not need to know how the broker work, or which broker you need - you just need the destination topic/queue and the message you have to send.
Once configured, you can inject the IMessageProducerFactory instance that you'll use to send a single message
[ApiController]
[Route("[controller]")]
public class MyApiController(IMessageProducerFactory producerFactory) : ControllerBase
{
private readonly IMessageProducerFactory producerFactory = producerFactory;
[HttpPost("Send/{topic}")]
public async Task<string> Get([FromRoute]string topic, [FromBody]Tester payload)
{
var producer = producerFactory.Producer(topic);
var msgId = await producer.SendAsync(payload);
return msgId;
}
}
Receive a message could be quite a pain, depending on the specific broker implementation.
OpenMessagingWrapperWrapper simplifies message management, you just need to provide, while adding a Consumer, a class, implementing IMessageConsumer.
Whenever a message is available for the specified topic, the method ConsumeAsync will be triggered, providing you basic info about the message.
You just need to specify if the message has been correctly processed (returning MessageAction.Complete), if it needs to be reprocessed (MessageAction.Requeue), or it should be discarded (MessageAction.Reject).
public class LoggerMqConsumer(ILogger<LoggerMqConsumer> logger) : IMessageConsumer
{
public Task<MessageAction> ConsumeAsync(MqMessage message)
{
logger.LogWarning("Message consumed: {0}", message.Body);
return Task.FromResult(MessageAction.Complete);
}
}
Sometimes, can happen that you message broker can fail, disconnected, crash, or whatever. When this happens, your services need to be restarted. If you're using a k8s cluster, you'll need to implement healthcheck for readiness and liveness, to tell your cluster when pods needs to be started again. OpenMessagingWrapperWrapper exploits the amazing features provided by Microsoft HealthChecks and adds some checks for the provided brokers and topics. You just need to build a simple liveness/readiness probe to use them
[ApiController]
[Route("[controller]")]
public class MyApiController(HealthCheckService healthCheckService) : ControllerBase
{
private readonly HealthCheckService healthCheckService = healthCheckService;
[HttpGet]
[Route("liveness")]
[Route("readiness")]
public async Task<IActionResult> Get()
{
HealthReport report = await healthCheckService.CheckHealthAsync();
return report.Status == HealthStatus.Healthy ? Ok(report) : StatusCode((int)HttpStatusCode.ServiceUnavailable, report);
}
}
Repository source code is available under MIT License, see license in the source.
OpenMessagingWrapperWrapper uses the confluent-kafka-dotnet library, which is distributed under Apache 2.0 license:
OpenMessagingWrapperWrapper uses the Apache.NMS.ActiveMQ library, which is distributed under Apache 2.0 license:
Thank you for considering to help out with the source code! If you'd like to contribute, please fork, fix, commit and send a pull request for the maintainers to review and merge into the main code base.
Getting started with Git and GitHub
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.0.3-alpha | 175 | 8/23/2024 |
| 0.0.2-alpha | 150 | 8/23/2024 |
| 0.0.1-alpha | 167 | 8/22/2024 |