RabbitMQ - 向所有消费者广播相同的消息

时间:2018-06-11 10:14:39

标签: java rabbitmq

在RabbitMQ中,我要求向每个消费者广播相同的消息。一旦消费者请求到来,以下代码将从队列中删除消息。我需要做什么代码级别的修复才能完成这项任务?

ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
factory.setUsername("username");
factory.setPassword("password");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();

channel.queueDeclare("QUEUE_NAME", false, false, false, null);

channel.basicPublish("", "QUEUE_NAME", null, "Hello".getBytes("UTF-8"));
System.out.println(message + " sent");

channel.close();
connection.close();

提前致谢

0 个答案:

没有答案