RabbitMQ远程访问

http://www.blogjava.net/qileilove/archive/2014/09/04/417662.html

http://qaseven.github.io

http://www.linuxidc.com/Linux/2014-10/107917.htm

package com.mq.rabbitmq.rabbitmqtest;
import java.util.Date;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.QueueingConsumer;
public class ReceiveTest {
private final static String QUEUE_NAME = "ftpAgent";
private final static String userName = "admin";
private final static String password = "admin";
private final static String virtualHost = "/";
private final static int portNumber = 5672;
private final static String hostName = "master";
private final static String host = "192.168.174.132";
public static void main(String[] argv) throws java.io.IOException,
java.lang.InterruptedException {
ConnectionFactory factory = new ConnectionFactory();
//      factory.setHost("192.168.174.160");
factory.setUsername(userName);
factory.setPassword(password);
//      factory.setVirtualHost(virtualHost);
factory.setHost(host);
factory.setPort(portNumber);
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
//      channel.queueDeclare(QUEUE_NAME, false, false, false, null);
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(QUEUE_NAME, true, consumer);
Date nowTime = new Date();
while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
String message = new String(delivery.getBody());
System.out.println("RecieveTime: " + nowTime);
System.out.println(" [x] Received '" + message + "'");
}
}
}

ReceiveTest:

package com.mq.rabbitmq.rabbitmqtest;
import java.util.Date;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.QueueingConsumer;
public class ReceiveTest {
private final static String QUEUE_NAME = "ftpAgent";
private final static String userName = "admin";
private final static String password = "admin";
private final static String virtualHost = "/";
private final static int portNumber = 5672;
private final static String hostName = "master";
private final static String host = "192.168.174.132";
public static void main(String[] argv) throws java.io.IOException,
java.lang.InterruptedException {
ConnectionFactory factory = new ConnectionFactory();
//      factory.setHost("192.168.174.160");
factory.setUsername(userName);
factory.setPassword(password);
//      factory.setVirtualHost(virtualHost);
factory.setHost(host);
factory.setPort(portNumber);
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
//      channel.queueDeclare(QUEUE_NAME, false, false, false, null);
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(QUEUE_NAME, true, consumer);
Date nowTime = new Date();
while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
String message = new String(delivery.getBody());
System.out.println("RecieveTime: " + nowTime);
System.out.println(" [x] Received '" + message + "'");
}
}
}


阅读更多
文章标签: java
个人分类: 网络编程
上一篇解决/lib64/libc.so.6: version `GLIBC_2.14' not found
下一篇Linux信号(signal) 分析与处理
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭