rabbitMQ Connection超时

时间:2016-03-23 08:36:12

标签: java rabbitmq virtual-machine

我在vm上运行了rabbitMQ服务器。 我正在关注rabbitMQ java教程。 它在vm本地工作正常但是当尝试从主机发送时我得到一个异常

Exception in thread "main" java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at com.rabbitmq.client.impl.FrameHandlerFactory.create(FrameHandlerFactory.java:32)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:714)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:760)
at Send.main(Send.java:16)

这是我正在使用的发送代码:

import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import java.util.concurrent.TimeoutException;
import com.rabbitmq.client.Channel;

public class Send {
    private final static String QUEUE_NAME = "hello";

    public static void main(String[] args) throws java.io.IOException, TimeoutException {

            ConnectionFactory factory = new ConnectionFactory();
            factory.setHost("192.168.198.100");
            factory.setPort(5672);
            Connection connection = factory.newConnection();
            Channel channel = connection.createChannel();

            channel.queueDeclare(QUEUE_NAME, false, false, false, null);
            String message = "Hello World from Windows!";
            channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
            System.out.println(" [x] Sent '" + message + "'");

            channel.close();
            connection.close();

        }
    }

我可以在192.168.198.100 ping服务器,但我无法访问管理界面 192.168.198.100:15672 /

所以有人可以帮我弄清楚这个问题有什么问题吗? 提前致谢。

1 个答案:

答案 0 :(得分:3)

1

您使用guest guest作为凭据,并且不允许使用远程IP。

请阅读:Can't access RabbitMQ web management interface after fresh install 然后你必须添加这个:

factory.setPassword("test");
factory.setUsername("test");

2

您是否启用了管理用户界面?如果不使用:

rabbitmq-plugins enable rabbitmq_management

3

检查防火墙配置可能是端口5672和15672已关闭。 您可以使用telnet来测试端口:

telnet 192.168.198.100 5672
Trying 192.168.198.100...
Connected to 192.168.198.100.
Escape character is '^]'.

telnet 192.168.198.100 15672
Trying 192.168.198.100...
Connected to 192.168.198.100.
Escape character is '^]'.