/EventBus

All Message Queue (MQ) Software producer and consumer (ActiveMQ, AmazonSQS, AzureStorageQueues, GoogleCloudPubSub, IBMMQ, Kafka, RabbitMQ, ServiceBus ...) samples with .NET Core and deploy docker

Primary LanguageC#

ALL Message Queue (MQ) with .NET Core

All Message Queue (MQ) Software producer and consumer (ActiveMQ, AmazonSQS, AzureStorageQueues, GoogleCloudPubSub, IBMMQ, Kafka, RabbitMQ, ServiceBus ...) samples with .NET Core and deploy docker

Event Bus Sample Producer Sample Consumer deploy docker-compose
EventBus.ActiveMQ Sample.ActiveMQ.Producer Sample.ActiveMQ.Consumer docker-compose.activemq.yml
EventBus.AmazonSQS Sample.AmazonSQS.Producer Sample.AmazonSQS.Consumer docker-compose.amazonsqs.yml
EventBus.AzureStorageQueues Sample.AzureStorageQueues.Producer Sample.AzureStorageQueues.Consumer docker-compose.azurestoragequeues.yml
EventBus.GoogleCloudPubSub Sample.GoogleCloudPubSub.Producer Sample.GoogleCloudPubSub.Consumer docker-compose.googlecloudpubsub.yml
EventBus.IBMMQ Sample.IBMMQ.Producer Sample.IBMMQ.Consumer docker-compose.ibmmq.yml
EventBus.Kafka Sample.Kafka.Producer Sample.Kafka.Consumer docker-compose.Kafka.yml
EventBus.RabbitMQ Sample.RabbitMQ.Producer Sample.RabbitMQ.Consumer docker-compose.rabbitmq.yml
EventBus.ServiceBus Sample.ServiceBus.Producer Sample.ServiceBus.Consumer docker-compose.servicebus.yml

A new Mq integration and project template

-- src
    |
    | -- Samples
            |
            | -- deploy
                    |
                    | -- docker-compose.newmq.yml
                    | ...
            | -- Sample.NewMq.Consumer
            | -- Sample.NewMq.Producer
            | ...
            | -- Sample.Shared
    | -- EventBus
    | -- EventBus.NewMq
    | ...


Usage

  • Event type
public class your_event_type : IntegrationEvent
{
    //TODO:...
}
  • Subscribe handler
public class your_subscribe_handler_type : IIntegrationEventHandler<your_event_type>
{
    //TODO:...
    public async Task Handle(your_event_type @event)
    {
        //TODO:....
    }
}
  • Add subscriber type and event subscribe
var eventBus = serviceProvider.GetRequiredService<IEventBus>();
eventBus.Subscribe<your_event_type, your_subscribe_handler_type>();
  • Event publish
var eventBus = serviceProvider.GetRequiredService<IEventBus>();
var @event = new your_event_type{ /*TODO:...*/};
eventBus.Publish(@event);
  • Register DI subscriber handler
services.AddTransient<your_subscribe_handler_type>();
//TODO:...
  • Register DI MQ subscriptions manager
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
  • Register DI your MQ persistent connection
services.AddSingleton<your_mq_PersistentConnection>(sp =>
{
    var config = ....
    var logger = sp.GetRequiredService<ILogger<Default_your_mq_PersistentConnection>>();
    return new Default_your_mq_PersistentConnection(logger, config);
});
  • Register DI your MQ
services.AddSingleton<IEventBus, EventBus_your_mq>(sp =>
{
    var persistentConnection = sp.GetRequiredService<your_mq_PersistentConnection>();
    var iLifetimeScope = sp.GetRequiredService<ILifetimeScope>();
    var logger = sp.GetRequiredService<ILogger<EventBus_your_mq>>();
    var eventBusSubcriptionsManager = sp.GetRequiredService<IEventBusSubscriptionsManager>();

    return new EventBus_your_mq(persistentConnection, logger, iLifetimeScope, eventBusSubcriptionsManager);
});