MassTransit
MassTransit message bus event handling implementation in RCommon
Overview
MassTransit is a framework that abstracts away the complexities of messaging queues and distributed computing at large. It is perhaps one of the best message bus implementations in the .NET ecosystem and is incredibly feature rich.
MassTransit is very well documented and well supported by the open source community.
Configuration
using Examples.Messaging.MassTransit;
using MassTransit;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using RCommon;
using RCommon.EventHandling;
using RCommon.EventHandling.Producers;
using RCommon.MassTransit;
using RCommon.MassTransit.Producers;
using System.Diagnostics;
try
{
var host = Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((context, builder) =>
{
ConfigurationContainer.Configuration = builder
.Build();
})
.ConfigureServices(services =>
{
// Configure RCommon
services.AddRCommon()
.WithEventHandling<MassTransitEventHandlingBuilder>(eventHandling =>
{
// This is a wrapper for MassTransit configuration
eventHandling.UsingInMemory((context, cfg) =>
{
cfg.ConfigureEndpoints(context);
});
// A simple and consistent interface for adding producers and subscribers
eventHandling.AddProducer<PublishWithMassTransitEventProducer>();
eventHandling.AddSubscriber<TestEvent, TestEventHandler>();
});
services.AddHostedService<Worker>();
}).Build();
await host.RunAsync();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Implementation
Producing the Event
Subscribing to the Event
Event Handling: MassTransitLast updated