首页 > 代码库 > RabbitMQ文档翻译——Hello World!(下)
RabbitMQ文档翻译——Hello World!(下)
Receiving
源码:
1 package Consuming; 2 3 import com.rabbitmq.client.*; 4 5 import java.io.IOException; 6 7 /** 8 * Created by zhengbin06 on 16/9/11. 9 */10 public class Recv {11 private final static String QUEUE_NAME = "hello";12 13 public static void main(String[] argv)14 throws java.io.IOException,15 java.lang.InterruptedException {16 17 ConnectionFactory factory = new ConnectionFactory();18 factory.setHost("localhost");19 // factory.setPort(5672);20 Connection connection = factory.newConnection();21 Channel channel = connection.createChannel();22 channel.queueDeclare(QUEUE_NAME, false, false, false, null);23 System.out.println(" [*] Waiting for messages. To exit press CTRL+C");24 Consumer consumer = new DefaultConsumer(channel) {25 @Override26 public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body)27 throws IOException {28 String message = new String(body, "UTF-8");29 System.out.println(" [x] Received ‘" + message + "‘");30 }31 };32 channel.basicConsume(QUEUE_NAME, true, consumer);33 }34 }
java运行命令
java -cp命令解释
RabbitMQ文档翻译——Hello World!(下)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。