-
Notifications
You must be signed in to change notification settings - Fork 14
Producer
Brian Lehnen edited this page Dec 8, 2020
·
6 revisions
The message can be any serializable class.
Creating the queue is pretty straightforward. You'll need to specify the transport you want to use.
var queueConnection = new QueueConnection(queueName, connectionString);
using (var queueContainer = new QueueContainer<InitModule>())
{
using (var queue = queueContainer.CreateProducer<YourMessageClass>(queueConnection))
{
...
}
}
If you dispose of the container, all queues created from the container will be disposed as well. If you will be sending many messages over time, you should hang on to the container/queues instead of constantly creating them.
The send commands are thread safe.
Messages can be sent in a few different ways.
var result = queue.Send(new SimpleMessage {Message = "Hello World"});
var data = new AdditionalMessageData();
data.SetDelay(TimeSpan.FromMinutes(1));
var result = queue.Send(new SimpleMessage {Message = "Hello World"}, data);
A collection of messages with or without additional metadata. Note that this operation is not necessarily atomic
var result = queue.Send(messageList);
var result = await queue.SendAsync(new SimpleMessage {Message = "Hello World"});
All methods return the result of the operation. This includes the following:
- A boolean indicating if an error occurred
- An exception containing the error, if an error occurred.
- Information about the sent message, assuming no errors -The message ID -The correlation ID
Methods that take in a collection of messages return a collection of results. The collection contains a boolean named 'HasErrors' that will indicate if any result failed.
For any issues please use the GitHub issues