|
@@ -24,14 +24,17 @@ public class ConsumerDemo {
|
|
String queueName = "testQueue";
|
|
String queueName = "testQueue";
|
|
channel.queueDeclare( queueName, false, false, false, null );
|
|
channel.queueDeclare( queueName, false, false, false, null );
|
|
|
|
|
|
|
|
+ //监听队列消息, 如果有消息则会回调客户端
|
|
channel.basicConsume(queueName, new DefaultConsumer(channel){
|
|
channel.basicConsume(queueName, new DefaultConsumer(channel){
|
|
|
|
|
|
|
|
+ //处理消息函数
|
|
public void handleDelivery(String consumerTag,
|
|
public void handleDelivery(String consumerTag,
|
|
Envelope envelope,
|
|
Envelope envelope,
|
|
AMQP.BasicProperties properties,
|
|
AMQP.BasicProperties properties,
|
|
byte[] body)
|
|
byte[] body)
|
|
throws IOException
|
|
throws IOException
|
|
{
|
|
{
|
|
|
|
+ //我们收到消息后打印消息
|
|
System.out.println( new String( body ) );
|
|
System.out.println( new String( body ) );
|
|
}
|
|
}
|
|
|
|
|