rabbitmq五---接收符合特定路由规则的消息
来源:互联网 发布:软件系统设计方法 编辑:程序博客网 时间:2024/05/18 12:03
发送端:
channel.exchangeDeclare(EXCHANGE_NAME, "topic");//声明topic类型的ExchangeString routingKeyOne = "logs.error.one";// 定义一个路由名为“error”for (int i = 0; i <= 1; i++) { String messageOne = "this is one error logs:" + i; channel.basicPublish(EXCHANGE_NAME, routingKeyOne, null, messageOne.getBytes()); System.out.println(" [x] Sent '" + routingKeyOne + "':'"+ messageOne + "'"); } System.out.println("################################"); String routingKeyTwo = "logs.error.two"; for (int i = 0; i <= 2; i++) { String messageTwo = "this is two error logs:" + i; channel.basicPublish(EXCHANGE_NAME, routingKeyTwo, null, messageTwo.getBytes()); System.out.println(" [x] Sent '" + routingKeyTwo + "':'" + messageTwo + "'"); } System.out.println("################################"); String routingKeyThree = "logs.info.one"; for (int i = 0; i <= 3; i++) { String messageThree = "this is one info logs:" + i; channel.basicPublish(EXCHANGE_NAME, routingKeyThree, null,messageThree.getBytes()); System.out.println(" [x] Sent '" + routingKeyThree + "':'"+ messageThree + "'"); } channel.close(); connection.close();
接收端1:
channel.exchangeDeclare(EXCHANGE_NAME, "topic");// 声明topic类型的ExchangeString queueName = "queue_topic_logs1";// 定义队列名为“queue_topic_logs1”的Queuechannel.queueDeclare(queueName, false, false, false, null); // String routingKeyOne = "*.error.two";// "error"路由规则// channel.queueBind(queueName, EXCHANGE_NAME, routingKeyOne);// 把Queue、Exchange及路由绑定String routingKeyTwo = "logs.*.one";//通配所有logs下第三词(最后一个)词为one的消息channel.queueBind(queueName, EXCHANGE_NAME, routingKeyTwo); System.out.println(" [*] Waiting for messages."); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(queueName, true, consumer); while (true) { QueueingConsumer.Delivery delivery = consumer.nextDelivery(); String message = new String(delivery.getBody()); String routingKey = delivery.getEnvelope().getRoutingKey(); System.out.println(" [x] Received '" + routingKey + "':'" + message + "'"); }
接收端2:
channel.exchangeDeclare(EXCHANGE_NAME, "topic");//声明topic类型的ExchangeString queueName = "queue_topic_logs2";//定义队列名为“queue_topic_logs2”的Queuechannel.queueDeclare(queueName, false, false, false, null); String routingKeyOne = "logs.#";//通配所有logs下的消息channel.queueBind(queueName, EXCHANGE_NAME, routingKeyOne);//把Queue、Exchange及路由绑定System.out.println(" [*] Waiting for messages."); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(queueName, true, consumer); while (true) { QueueingConsumer.Delivery delivery = consumer.nextDelivery(); String message = new String(delivery.getBody()); String routingKey = delivery.getEnvelope().getRoutingKey(); System.out.println(" [x] Received '" + routingKey + "':'" + message + "'"); }
- rabbitmq五---接收符合特定路由规则的消息
- rabbitmq四---通过路由规则,接收端接收发送端发送的消息
- RabbitMQ(part4某消费者只接收符合某种绑定秘钥和路由秘钥的消息)----Routing
- RabbitMQ(五):消息路由
- rabbitMQ学习笔记(五) 消息路由
- rabbitMQ学习笔记(五) 消息路由
- RabbitMQ消息队列(五):Routing 消息路由
- RabbitMQ消息队列(五):Routing 消息路由
- RabbitMQ消息队列(五):Routing 消息路由(转)
- RabbitMQ消息队列(五):Routing 消息路由
- RabbitMQ消息队列(五):Routing 消息路由
- RabbitMQ消息队列(五):Routing 消息路由
- RabbitMQ消息队列(五):Routing 消息路由
- RabbitMQ消息队列(五):Routing 消息路由
- RabbitMQ消息队列(五):Routing 消息路由
- RabbitMQ消息队列(五):Routing 消息路由[转]
- RabbitMQ消息队列(五):Routing 消息路由[转]
- RabbitMQ消息队列(五):Routing 消息路由
- vim
- 使用SQL进行模糊查询
- hdfs 常用java API---代码篇(一)
- 9月7日 Warming Up 总结
- 转载:PostgreSQL学习手册(六) 索引
- rabbitmq五---接收符合特定路由规则的消息
- Android Bluetooth蓝牙开发\蓝牙协议\蓝牙通信例子_Android支持蓝牙4.0版本_BLE开发
- shell中用指定用户运行命令 su
- 手机Web
- uva 437 The Tower of Babylon(DAG最长路)
- 使用query()方法进行模糊查询
- Android调用Camera实现自定义照相
- poj.1328贪心
- HDU 3341 Lost's revenge (AC自动机+DP,5级)