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
-
IAsyncHealthCheckProvider<IConnection>
- 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
marshallerIMarshallerThe marshaller used for serializing and deserializing messages.
optionsRabbitMqCommandQueueOptionsThe options used to configure the RabbitMQ command queue.
Exceptions
- ArgumentNullException
marshallercannot be null -or-optionscannot be null.- ArgumentException
optionsare 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
setupAction<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
messagesIEnumerable<IMessage<ICommand>>The messages to send.
setupAction<AsyncOptions>The AsyncOptions which may be configured.