|
@@ -1,8 +1,13 @@
|
|
package com.lovecoding.rabbitmq.consumer;
|
|
package com.lovecoding.rabbitmq.consumer;
|
|
|
|
|
|
|
|
+import com.rabbitmq.client.AMQP;
|
|
|
|
+import com.rabbitmq.client.Channel;
|
|
|
|
+import org.springframework.amqp.core.Message;
|
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
+
|
|
@Component
|
|
@Component
|
|
public class ConsumerTemplate {
|
|
public class ConsumerTemplate {
|
|
|
|
|
|
@@ -58,4 +63,37 @@ public class ConsumerTemplate {
|
|
System.out.println( "哈尔滨天气:" + msg );
|
|
System.out.println( "哈尔滨天气:" + msg );
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @RabbitListener(queues = "topicQueue")
|
|
|
|
+ public void t7( String msg){
|
|
|
|
+ System.out.println( "北京天气:" + msg );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @RabbitListener(queues = "topicQueueT8")
|
|
|
|
+ public void t8( String msg){
|
|
|
|
+ System.out.println( "哈尔滨天气:" + msg );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @RabbitListener(queues = "topicQueueT9")
|
|
|
|
+ public void t9( String msg){
|
|
|
|
+ System.out.println( "通用天气:" + msg );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @RabbitListener(queues = "deadQueueDemo")
|
|
|
|
+ public void t10(Message msg, Channel channel){
|
|
|
|
+
|
|
|
|
+ long deliveryTag = msg.getMessageProperties().getDeliveryTag();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ channel.basicNack(deliveryTag, false, false);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ System.out.println( "收到消息:" + msg );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+// @RabbitListener(queues = "deadQueue")
|
|
|
|
+// public void t11(String msg){
|
|
|
|
+// System.out.println( "收到死信:" + msg );
|
|
|
|
+// }
|
|
|
|
+
|
|
}
|
|
}
|