在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();
提前致谢