fanout 发送端
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
public class MyFanoutSender {
private static final String MESSAGE = "my name is";
public static void main(String[] args){
Connection conn = null;
Channel channel = null;
try {
//初始化连接,主机,端口,用户名,密码可以自己定义
ConnectionFactory factory = new ConnectionFactory();
factory.setHost(HOST_PARAMETER.LOCAL_HOST);
factory.setPort(HOST_PARAMETER.LOCAL_PORT);
factory.setUsername(HOST_PARAMETER.LOCAL_USER_NAME);
factory.setPassword(HOST_PARAMETER.LOCAL_PASSWORD);
//创建连接
conn = factory.newConnection();
//创建通道
channel = conn.createChannel();
//定义为fanout类型的交换机
channel.exchangeDeclare(HOST_PARAMETER.EXCHANGE_NAME, "fanout");
//发送,指定routingkey为"