Table of Contents

Class RabbitMqCommandQueue

Namespace
Savvyio.Extensions.RabbitMQ.Commands
Assembly
Savvyio.Extensions.RabbitMQ.dll

Provides a default implementation of the RabbitMqMessage class for messages holding an ICommand implementation.

public class RabbitMqCommandQueue : RabbitMqMessage, IDisposable, IAsyncDisposable, IAsyncHealthCheckProvider<IConnection>, IPointToPointChannel<ICommand>, ISender<ICommand>, IReceiver<ICommand>
Inheritance
RabbitMqCommandQueue
Implements
Derived
Inherited Members

Examples

RabbitMqCommandQueue publishes and receives commands through RabbitMQ. Configure it with RabbitMqCommandQueueOptions and use it as IPointToPointChannel<ICommand>.

using System;
using Savvyio.Commands;
using Savvyio.Extensions.RabbitMQ.Commands;
using Savvyio.Messaging;

namespace ExampleApp;

public class RabbitMqCommandQueueConfig
{
    public static RabbitMqCommandQueueOptions CreateOptions()
    {
        return new RabbitMqCommandQueueOptions { AmqpUrl = new Uri("amqp://guest:guest@localhost:5672"), QueueName = "account-commands", Durable = true };
    }

    public static IPointToPointChannel<ICommand> AsChannel(RabbitMqCommandQueue queue) => queue;
}

Constructors

RabbitMqCommandQueue(IMarshaller, RabbitMqCommandQueueOptions)

Initializes a new instance of the RabbitMqCommandQueue class.

public RabbitMqCommandQueue(IMarshaller marshaller, RabbitMqCommandQueueOptions options)

Parameters

marshaller IMarshaller

The marshaller used for serializing and deserializing messages.

options RabbitMqCommandQueueOptions

The options used to configure the RabbitMQ command queue.

Exceptions

ArgumentNullException

marshaller cannot be null -or- options cannot be null.

ArgumentException

options are not in a valid state.

Methods

ReceiveAsync(Action<AsyncOptions>)

Receives command messages asynchronously from the configured RabbitMQ queue.

public IAsyncEnumerable<IMessage<ICommand>> ReceiveAsync(Action<AsyncOptions> setup = null)

Parameters

setup Action<AsyncOptions>

The AsyncOptions which may be configured.

Returns

IAsyncEnumerable<IMessage<ICommand>>

An IAsyncEnumerable<T> that yields IMessage<T> instances as they are received.

SendAsync(IEnumerable<IMessage<ICommand>>, Action<AsyncOptions>)

Sends the specified command messages asynchronously to the configured RabbitMQ queue.

public Task SendAsync(IEnumerable<IMessage<ICommand>> messages, Action<AsyncOptions> setup = null)

Parameters

messages IEnumerable<IMessage<ICommand>>

The messages to send.

setup Action<AsyncOptions>

The AsyncOptions which may be configured.

Returns

Task

A Task that represents the asynchronous operation.

See Also