LightMediator.EventBus.MQTT
0.5.2.3
dotnet add package LightMediator.EventBus.MQTT --version 0.5.2.3
NuGet\Install-Package LightMediator.EventBus.MQTT -Version 0.5.2.3
<PackageReference Include="LightMediator.EventBus.MQTT" Version="0.5.2.3" />
<PackageVersion Include="LightMediator.EventBus.MQTT" Version="0.5.2.3" />
<PackageReference Include="LightMediator.EventBus.MQTT" />
paket add LightMediator.EventBus.MQTT --version 0.5.2.3
#r "nuget: LightMediator.EventBus.MQTT, 0.5.2.3"
#:package LightMediator.EventBus.MQTT@0.5.2.3
#addin nuget:?package=LightMediator.EventBus.MQTT&version=0.5.2.3
#tool nuget:?package=LightMediator.EventBus.MQTT&version=0.5.2.3
LightMediator.EventBus.MQTT
LightMediator.EventBus.MQTT is an extension for LightMediator and LightMediator.EventBus that adds distributed messaging support using MQTT.
It enables publishing and subscribing to INotification
messages between services, applications, or domains in a decoupled and scalable way — powered by MQTT and your high-performance, lightweight mediator.
✨ Features
- 🔄 Publish/Subscribe model over MQTT.
- 💡 Built on top of
LightMediator.EventBus
. - 🔌 Easy integration with minimal configuration.
- 🔒 Supports durable queues and automatic reconnects.
📦 Installation
Install via NuGet:
dotnet add package LightMediator.EventBus.MQTT
Or via the Package Manager:
Install-Package LightMediator.EventBus.MQTT
🚀 Getting Started
1. Register LightMediator with MQTT support
In your Program.cs
or Startup.cs
:
builder.Services.AddLightMediator(options =>
{
options.IgnoreNamespaceInAssemblies = true;
options.IgnoreNotificationDifferences = true;
options.RegisterNotificationsByAssembly = true;
options.RegisterRequestsByAssembly = true;
options.Assemblies = new[]
{
Assembly.GetExecutingAssembly(),
Lib1.GetServiceAssembly(),
Lib2.GetServiceAssembly(),
Service1.GetServiceAssembly()
};
options.AddLightMediatorEventBus(services)
.UseMQTT(builder.Configuration.GetSection("MQTTSettings"));
});
2. Create a Notification
using LightMediator;
namespace WorkerService1.Events;
internal class TestEvent:INotification
{
public string MyProperty { get; set; }
}
3. Handle the Notification in another service
using LightMediator;
using WorkerService2.Events;
namespace WorkerService2.EventHandlers;
internal class TestEventHandler : NotificationHandler<TestEvent>
{
private readonly ILogger<TestEventHandler> _logger;
public TestEventHandler(ILogger<TestEventHandler> logger)
{
_logger = logger;
}
public override Task Handle(TestEvent message, CancellationToken? cancellationToken)
{
_logger.LogInformation($"___________________Event recieved__________________ {message.MyProperty}");
return Task.CompletedTask;
}
}
4. Publish a Notification as a Event using eventbus extension method
await _mediator.PublishEvent(new TestEvent() { MyProperty = "Hello"});
The message will be delivered to all services that registered the same
ExchangeName
and are listening for that notification.
5. Publish a message to Extra topics
Subscribe:
builder.Services.AddLightMediator(o =>
{
o.IgnoreNamespaceInAssemblies = true;
o.IgnoreNotificationDifferences = true;
o.RegisterNotificationsByAssembly = true;
o.RegisterRequestsByAssembly = true;
o.Assemblies = new[]
{
Assembly.GetExecutingAssembly()
};
o.AddLightMediatorEventBus(builder.Services)
.UseMQTT(builder.Configuration.GetSection("MQTTSettings"), mqtto => mqtto.AddTopics("pro","main"));
});
Publish:
await _mediator.PublishEvent(new TestEvent() { MyProperty = "Hello"}, extraTopics: "pro");
The message will be delivered to all services that registered the same Topics and are listening for that notification.
📝 License
This project is licensed under the MIT License.
Created with ❤️ by @omidmloo
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- LightMediator.EventBus (>= 0.5.2.1)
- MQTTnet (>= 5.0.1.1416)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
- Update light mediator to use system.text.json