【问题标题】:How to get messages from the rabbitmq server which is installed in another machine如何从安装在另一台机器上的 rabbitmq 服务器获取消息
【发布时间】:2013-08-25 05:12:08
【问题描述】:

***大家好

我有两台机器,一台是真实的,另一台是Vmware Workstation安装的。它们通过NAT连接

真正的(主机)设置为: IP:192.168.241.1 子网掩码:255.255.255.0 网关IP:192.168.241.2

并且虚拟机设置为: IP:192.168.241.11 子网掩码:255.255.255.0 网关IP:192.168.241.2

我已经在主机和虚拟机上安装了rabbitmq。

我在我的主机上运行这段代码:

ConnectionFactory factorySTC = new ConnectionFactory();
factorySTC.setHost("localhost");
factorySTC.setPort(5672);
Connection connectionSTC = factorySTC.newConnection();
Channel channelSTC = connectionSTC.createChannel();
channelSTC.queueDeclare("queue", true, false, false, null);
String message="helloworld";       
channelSTC.basicPublish("","queue",
MessageProperties.PERSISTENT_TEXT_PLAIN,message.getBytes());

我的意思是,我想发送“地狱世界”到队列“队列”

我在我的主机上运行这段代码(上面的 ip 设置为 192.168.241.11):

ConnectionFactory factorySTC = new ConnectionFactory();
factorySTC.setHost("192.168.241.1");
factorySTC.setPort(5672);
Connection connectionSTC = factorySTC.newConnection();
Channel channelSTC = connectionSTC.createChannel();
channelSTC.queueDeclare("queue", true, false, false, null);
QueueingConsumer cosumerSTC=new QueueingConsumer(channelSTC);
QueueingConsumer.Delivery delivery = cosumerSTC.nextDelivery();
String message = new String(delivery.getBody());

但它不起作用。它失败了,并且显示“连接超时....”

那么,如何解决这个问题?我的意思是,我想从安装在与我的电脑在同一个 LAN 中的机器上的 rabbitmq 队列中获取消息...

提前非常非常非常感谢...

问候...

【问题讨论】:

    标签: java rabbitmq vmware lan


    【解决方案1】:

    您不需要在第二台机器上安装rabbitmq 服务器。重点是您有一台服务器,并且每台其他机器都发布到队列/交换并从一台服务器上的队列中读取。其次,如果您遇到连接超时,则说明您遇到了网络问题,很可能是防火墙问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-06
      • 2018-04-27
      • 1970-01-01
      相关资源
      最近更新 更多