Provides message reading and conversion for a RabbitMQ source.
PM> install-package Overseer.RabbitMQ
var reader = new RabbitMessageReader(new RabbitOptions
{
HostName = "192.168.59.103",
ExchangeName = "DomainEvents"
});
//...
var monitor = new QueueMonitor(reader, new RabbitMessageConverter(), validationSource, output);
The reader assumes you have an exchange of type Topic
, and will bind a temporary queue to this exchange to read messages with. Exchange Name, Durability and AutoDelete can all be configured, and setting SkipExchangeDeclare will force no .ExchangeDeclare()
call to be made at all.
The configuration options for RabbitMessageReader
The RabbitMQ host to connect to.
options.HostName = "192.168.59.103";
The exchange to bind a queue to.
.ExchangeName = "DomainEvents";
The routing key to use to filter messages. Defaults to #
.
options.RoutingKey = "#"; //all messages
options.RoutingKey = "People.*";
Whether the exchange is durable (e.g. will survive a RabbitMQ restart). Defaults to true
.
options.ExchangeDurable = true;
Whether to delete the exchange when all queues bound to it have been removed. Defaults to false
.
options.ExchangeAutoDelete = false;
Prevents .ExchangeDeclare()
from being called. Defaults to false
. When set to true
, ExchangeDurable
, ExchangeAutoDelete
values are ignored.
options.ExchangeSkipDeclare = false;
The converter assumes two things: that the message body is a UTF8 Byte Array
(or null), which it will convert to a string representation; and that the Type
property on the BasicDeliverEventArgs
is populated with the message type (which is used to locate the correct validationSource
).
If you need to do conversion differently, re-implementing the RabbitMessageConverter
is very straight forward. See the source of it for more details.