RabbitMQ_ExchangeType Topic(4)

Exchange: Exchange is a rout map
ExchangeType: Topic, the message will be pushed to the specified queues which are matched to the Routingkey like regular expression.
1.Send project code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 TopicExchangeTest(args, "TopicQueue");
static void TopicExchangeTest(string[] args, string quename)
{
var factory = new ConnectionFactory() { HostName = "localhost" };
using (var connection = factory.CreateConnection())
{
using (var channel = connection.CreateModel())
{
string exchangeName = "TopicTest";
string routingKey = "TopicRK.*"; //* for single word ,# for multiple words
channel.ExchangeDeclare(exchangeName, ExchangeType.Topic, false, false, null);
channel.QueueDeclare(queue: quename, durable: false, exclusive: false, autoDelete: false, arguments: null);
channel.QueueBind(quename, exchangeName, routingKey, null);
string message = args.Length > 0 ? exchangeName + " " + args[0] : "Hello RabbitMQ";
var body = Encoding.UTF8.GetBytes(message);
channel.BasicPublish(exchangeName, "TopicRK.one", basicProperties: null, body: body);
Console.WriteLine("[x] Sent {0} ", message);

}
}
}


2.Receive project code:
1
ConsumeMsg(args, "TopicQueue");

3.Run command for Send,The Routingkey is “TopicRK.one”

4.Run command for Receive

5.Publish a message and The Routingkey is “TopicRK.one.123”, The message will not be routed