网站首页> 文章专栏> RabbitMQ-java客户端-Topic
Java客户端-Topic交互机
1,创建队列和交换机
topic.queue1
topic.queue2
hmall.topic
2,创建消费者
@Slf4j @Component public class SpringRabbitListener { @RabbitListener(queues = "topic.queue1") public void listenTopicQueueMessage1(String msg){ System.out.println("china.# topic.queue1:" + msg); } @RabbitListener(queues = "topic.queue2") public void listenTopicQueueMessage2(String msg){ System.out.println("#.news 收到了 topic.queue2:" + msg); } }
3,创建生产者
@Test
void testSendTopic() {
String exchangeNme = "hmall.topic";
String routingkey = "china.weather";
String msg = "今天天气";
rabbitTemplate.convertAndSend(exchangeNme,routingkey,msg);
}
2024-05-16 22:34:15 回复