RabbitMQ
There is a cool feature, routing based on the theme , this feature allows subscribers to filter messages based on multiple criteria. Theme is separated by a dot word list, published with the news. For example: "stock.usd.nyse" or "book.uk.london" or "abc", which can be any word you like, but usually some of the attributes of the message. The most restrictive topic string 255
characters.
To publish a theme, the theme of simple parameters by using the belt Publish
overloaded methods. "
bus.Publish(message,"X.A");
- 1
Subscribers can specify a theme to match to filter messages. These can include wildcards.
- * (Asterisk) can only match a word.
- (Pound sign) matches zero or more words.
Such a message is published with a theme of "XA2" will match "#", "X. #" , ".A.", But can not match "XB" or "A". To subscribe to a topic, use configuration with SubScribe
overloaded methods.
bus.Subscribe("my_id", handler,
x=>x.WithTopic("X.*"));
WARNING: with the same subscriberId
two separate subscription, but with a different theme strings, you may not have the desired effect. A subscriberId
fact to identify a separate AMQP
queue. With the same subscriberId
two subscribers will be connected simultaneously to the same queue, and add their own topics Binding
. For example, if you do this:
bus.Subscribe("my_id",handlerOfXDotStar,
x=>x.WithTopic("X.*")); bus.Subscribe("my_id",handlerOfStarDotB, x=>x.WithTopic(*.B));
It is possible to match the "X." or ".B" message will be sent to "XXX_My_id" queue. RabbitMQ
Then take turns delivering messages between two consumers. handlerOfXDotStar
And handlerOfStarDotB
it will take turns to get the message.
Now, if you want to match multiple themes ( "X." or ".B") You can use the Subscribe another overloaded method with multiple parameters of theme, like this:
bus.Subscribe("my_id",handler,
x=>x.WithTopic("X.*").WithTopic("*.B"));
These topics also apply to overloaded SubscribeAsync
methods.
EasyNetQ
The default behavior, when generating the name of the queue, using the message type name + subscription Id. For example: PartyInvitation
the message type, namespace EasyNetQ.Tests.Integration
, generated for the queue name: EasyNetQ.Tests.Integration.PartyInvitation: EasyNetQ.Tests_schedulingTest1, subscription Id is assumed here schedulingTest1.
Control queue name
Controlling queue name, with Queue attribute
up message annotation category.
[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 use TestMessagesQueue
as the queue name, with MyTestExchange
a switch name. Note: pass Subscribe
method subscriptionsId
parameter is empty. If you specify subscriptionId
, it subscriptionId
will be appended to the name of the queue.
Let the message is not issued by EasyNetQ up and running
Use QueueAttribute
allows the consumer to regard any message queue. This can be used to consume messages posted As for other non EasyNetQ framework, as long as one condition: there are messages in the queue type property. type
Attribute value is used when the type of the message to determine the sequence of messages. As long as the property is set to some meaningful, the news can be consumed. Decoding type
name is ITypeNameSerializer.Deserialize
doing the method.
If you decide to use their own ITypeNameSerializer
implementation, so be careful how you perform deserialization method, if your implementation is CPU
computationally intensive, it is dangerous to limit the speed of your team a message. For example, the assembly is not the type of scan cache is a bad idea.
Named queue Notes
Set the queue name to an empty string will use the default naming convention. Queue names up to 255 characters (this is the RabbitMQ client
library mandatory). Queue name can be letters, numbers -
, underscores _
, dot .
, or colon :
. Queue name "amq." At the beginning, is set aside, in order to pre-defined and standardized queue