Skip to content

arttonoyan/MQTTnet.EventBus

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MQTTnet.EventBus

GitHub Nuget Nuget

Quick Start

In your ASP.NET Core Startup.cs file add the following

public void ConfigureServices(IServiceCollection services)
{
    //...

    var retryCount = 5;
    services.AddMqttEventBus(cfg =>
    {
        cfg
            .WithClientId("Api")
            .WithTcpServer("{Ip Address}", port: 1883);

    }, retryCount);
    services.AddTransient<MyEventHandler>();
}

An EventHandler is a class that may handle one or more message types. Each message type is defined by the IIntegrationEventHandler interface, where T is the MqttApplicationMessageReceivedEventArgs.

public class MyEventHandler : IIntegrationEventHandler
{
    public Task Handle(MqttApplicationMessageReceivedEventArgs args)
    {
        //Some action...
        return Task.CompletedTask;
    }
}

Then in your application add this extension

public static class ApplicationBuilderExtansions
{
    public static IApplicationBuilder UseEventBus(this IApplicationBuilder app, Action<IEventBus> action)
    {
        var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
        action.Invoke(eventBus);
        return app;
    }
}

and use it in your Startup.cs file

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    //...

    app.UseEventBus(async bus => 
    {
        await bus.SubscribeAsync<IntegrationEventHandler>("MyTopic1");
    });
}

Injected interfaces

  • IEventBus
  • IMqttPersisterConnection
  • IEventBusSubscriptionsManager

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%