All Message Queue (MQ) Software producer and consumer (ActiveMQ, AmazonSQS, AzureStorageQueues, GoogleCloudPubSub, IBMMQ, Kafka, RabbitMQ, ServiceBus ...) samples with .NET Core and deploy docker
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
| ...
- 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);
});