Liquid.Messaging.Aws

The Liquid.Messaging.Aws provides producer and consumer patterns to allow the send and consumption of Messaging inside your microservice. The main components are ILightProducer and ILightConsumer. This component allows send messages and consuming messages from AWS. This component is part of Liquid Application Framework.


Keywords
License
MIT
Install
Install-Package Liquid.Messaging.Aws -Version 2.0.2-alpha

Documentation

Liquid Application Framework - Messaging

This repository is part of the Liquid Application Framework, a modern Dotnet Core Application Framework for building cloud native microservices.

The main repository contains the examples and documentation on how to use Liquid.

Liquid Messaging

This package contains the messaging subsystem of Liquid, for interacting with assynchronous services. It also features several implementations. In order to use it, add the main package (Liquid.Messaging) to your project, along with the specific implementation that you will need.

Available Cartridges Badges
Liquid.Messaging.Aws Quality Gate Status
Liquid.Messaging.Azure Quality Gate Status
Liquid.Messaging.Gcp Quality Gate Status
Liquid.Messaging.Kafka Quality Gate Status
Liquid.Messaging.RabbitMq Quality Gate Status

Getting Started

This is a sample usage with Azure Service Bus cartridge

To publish a message, you must:

Register a producer in service provider

services.AddServiceBusProducer<MySampleMessage>("TestAzureServiceBus", "TestMessageTopic", false);

Include dependency in domain class constructor, and invoke this send method

using Liquid.Messaging;
public class MySampleProducer 
{
    //Dependency must be a ILightProducer implementation 
    private ILightProducer<MySampleMessage> _producer;

    public MySampleProducer(ILightProducer<MySampleMessage> producer)
    {
        _producer = producer;
    }
    public async Task Handle()
    {
        // Create a instance of message object defined as the type of the producer
        var message = new MySampleMessage();

         // Just invoke the Send method
        await _producer.SendMessageAsync(message, new Dictionary<string, object> { { "headerTest", "value" } });

    }
}

To consume messages, declare your subscriber :

public class MySampleConsumer : ServiceBusConsumer<MySampleMessage>
{
    public MySampleConsumer(IServiceProvider serviceProvider
        , IMediator mediator
        , IMapper mapper
        , ILightContextFactory contextFactory
        , ILightTelemetryFactory telemetryFactory
        , ILoggerFactory loggerFactory
        , ILightMessagingConfiguration<ServiceBusSettings> messagingConfiguration
        , ServiceBusConsumerParameter serviceBusConsumerParameter) 
        : base(serviceProvider, mediator, mapper, contextFactory, telemetryFactory, loggerFactory, messagingConfiguration, serviceBusConsumerParameter)
    {
    }

    //the consume async method is invoked when a message arrives
    public override async Task<bool> ConsumeAsync(MySampleMessage message, IDictionary<string, object> headers, CancellationToken cancellationToken)
    {
        // Do what you need with the message, usually translate to a command and send it to the Mediator Service
    }
}

Dependency Injection

//the value of the first parameter must be the name of the appsettings section where the connectionstring of this producer / consumer is defined.
services.AddServiceBusProducer<MySampleMessage>("TestAzureServiceBus", "TestMessageTopic", false);

services.AddServiceBusConsumer<MySampleConsumer, MySampleMessage>("TestAzureServiceBus", "TestMessageTopic", "TestMessageSubscription");

appsettings.json

 "liquid": {
    "messaging": {
      "azure": {
        "TestAzureServiceBus": {
          "connectionString": ""
        }
      }
    }
  }