1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
public class Consumer01 {
public static void main(String[] args) throws Exception{ Connection connection = RabbitMQUtil.getConnection(); Channel channel = connection.createChannel(); String queueName = channel.queueDeclare().getQueue();
channel.queueBind(queueName, "fanoutExchange", "");
System.out.println("消费者01等待接受消息..."); channel.basicConsume( queueName, (consumerTag, message) -> { System.out.println("接收消息:" + new String(message.getBody())); }, consumerTag -> { System.out.println("消息接收异常!"); } ); } }
|