RabbitMQ远程访问

转载 2016年06月01日 21:22:18

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远程连接调用Rabbitmq

打开IDEA创建一个maven工程(Java就可以了)。 pom.xml文件如下<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:...

RabbitMQ远程访问

http://www.blogjava.net/qileilove/archive/2014/09/04/417662.html http://qaseven.github.io http://ww...

我是如何成为一名python大咖的?

人生苦短,都说必须python,那么我分享下我是如何从小白成为Python资深开发者的吧。2014年我大学刚毕业..

C#访问远程主机资源的方法

转自:http://blog.csdn.net/csethcrm/article/details/20469929 实现访问远程主机的共享目录中的一个文件的解决方法: 一、调用Net us...

java 定制读取局域网共享文件,无需服务端

java 制定下载局域网共享文件 1、读取局域网文件类 import java.io.FileOutputStream; import jcifs.smb.SmbFile; import jcifs...

Ubuntu MySQL允许远程连接访问

前言:设置Ubuntu允许远程连接MySQL,出于安全方面考虑MySql-Server 只允许本机(localhost, 127.0.0.1)来连接访问. 这对于 Web-Server 与 MySql...

redis开启远程连接访问

redis默认只允许本地访问,要使redis可以远程访问可以修改redis.conf   打开redis.conf文件在NETWORK部分有说明   #####################...

TensorBoard以及远程访问(ssh端口转发)

一 TensorBoard简介TensorBoard是Tensorflow提供的可视化工具,TensorBoard可以有效地展示Tensorflow在运行过程中的计算图、各种指标随着时间的变化趋势以及...

MYSQL添加远程用户或允许远程访问三种方法

mysql添加远程用户或允许远程访问三种方法

mysql给root开启远程访问权限,修改root密码

mysql给root开启远程访问权限,修改root密码 1.MySql-Server 出于安全方面考虑只允许本机(localhost, 127.0.0.1)来连接访问. 这对于 ...

eclipse中将web项目部署到tomcat

eclipse中将web项目部署到tomcat.myeclipse部署WEB项目到tomcat比较方便,但eclipse貌似默认是不会替你将web自动部署到tomcat下的。你Run as该web项目...
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)