-
Notifications
You must be signed in to change notification settings - Fork 0
Controlling Queue names
The default behaviour of EasyNetQ, when generating names for queues, is to use message type name and append it with subscription Id. For example the PartyInvitation message type from namespace EasyNetQ.Tests.Integration will use queue name EasyNetQ.Tests.Integration.PartyInvitation:EasyNetQ.Tests_schedulingTest1, assuming that subscription Id is schedulingTest1.
To control the name of the queue, annotate the message class with Queue attribute:
[Queue("TestMessagesQueue", ExchangeName = "MyTestExchange")]
public class TestMessage
{
public string Text { get; set; }
}
// ...
bus.Subscribe<TestMessage>(string.Empty, msg => Console.WriteLine(msg.Text));
Here we tell EasyNetQ to use TestMessagesQueue as a queue name, and MyTestExchange as an exchange name. Notice that subscriptionId passed to Subscribe method is empty. If you specify subscriptionId then it will be appended to the end and used as queue name.
Using QueueAttribute allows to consume messages from any queue. This can be used to consume messages which are published by frameworks other than EasyNetQ as long as one condition is met - queue message has property type set. The value of type property is used during message de-serialization to determine type of the message. As long as this property is set to something meaningful, the messages may be consumed. Decoding type name is done in ITypeNameSerializer.Deserialize method.
Setting queue name to empty string will use default naming behaviour. The maximum length of queue name is 255 characters (this is enforced by RabbitMQ client library). The name can be a sequence of letters, digits, hyphen, underscore, period, or colon. Queue names starting with "amq." are reserved for pre-declared and standardised queues.
- Quick Start
- Introduction
- A Note on Versioning
- Installing EasyNetQ
- Connecting to RabbitMQ
- Connecting with SSL
- Logging
- Publish
- Subscribe
- Request Response
- Send Receive
- Topic Based Routing
- Controlling Queue names
- Polymorphic Publish and Subscribe
- Versioning Messages
- Publisher Confirms
- Scheduling Events with Future Publish
- Auto Subscriber
- Non Generic Publish & Subscription Extension Methods
- Error Conditions
- Re Submitting Error Messages With EasyNetQ.Hosepipe
- The Advanced API
- Cluster Support
- Wiring up EasyNetQ with TopShelf and Windsor
- Replacing EasyNetQ Components
- Using Alternative DI Containers