1.发布订阅模式下,消息会群发给所有的消费者,同一条消息所有的消费者都可以接收到
2.交换机:fanout交换机
3.生产者:定义交换机,向交换机发送消息
4.消费者:
(1)定义交换机
(2)定义随机队列
(3)与交换机绑定
(4)接收消息
5.发布订阅模式实战
package org.example.fanout;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import java.util.Scanner;
/**
* 生产者:发消息
*/
public class Producer {
// 交换机名称
public static final String EXCHANGE_NAME="fanout_logs";
public static void main(String[] args) throws Exception{
ConnectionFactory fa