EasyNetQ using (E) [theme-based routing, control queue name]

RabbitMQThere 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 255characters.

To publish a theme, the theme of simple parameters by using the belt Publishoverloaded 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 SubScribeoverloaded methods.

bus.Subscribe("my_id", handler, 
    x=>x.WithTopic("X.*"));

 

WARNING: with the same subscriberIdtwo separate subscription, but with a different theme strings, you may not have the desired effect. A subscriberIdfact to identify a separate AMQPqueue. With the same subscriberIdtwo 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. RabbitMQThen take turns delivering messages between two consumers. handlerOfXDotStarAnd handlerOfStarDotBit 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 SubscribeAsyncmethods.


EasyNetQThe 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 TestMessagesQueueas the queue name, with MyTestExchangea switch name. Note: pass Subscribemethod subscriptionsIdparameter is empty. If you specify subscriptionId, it subscriptionIdwill be appended to the name of the queue.

Let the message is not issued by EasyNetQ up and running

Use QueueAttributeallows 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 typename is ITypeNameSerializer.Deserializedoing the method.

If you decide to use their own ITypeNameSerializerimplementation, so be careful how you perform deserialization method, if your implementation is CPUcomputationally 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

Guess you like

Origin www.cnblogs.com/lhxsoft/p/11881566.html