在VM中部署了一个rabbitMQ server ,在物理机上按照rabbitMQ官网上的 java的教程访问VM中的rabbitMQ报如下错误:

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(); }
}

解决方案:

第一步.上面代码默认是使用rabbitMQ的默认用户“guest”作为登录用户,但是该用户不用许远程IP登录,所以我们需要自己在rabbitMQ中新增一个用户

//新增admin 密码admin
rabbitmqctl add_user admin admin    
//将admin用户设置为administrator
rabbitmqctl set_user_tags admin administrator
//给admin所有的权限
rabbitmqctl set_permissions -p / admin".*" ".*" ".*"

  然后增加如下Java代码:

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

第二.开启rabbitMQ的管理UI界面

rabbitmq-plugins enable rabbitmq_management

第三.检查防火墙是否开启了5672和15672端口,Centos7如何开启端口看这里

使用telnet测试

扩展.常见错误

1、如果写错了host (如:factory.setHost("locathost"); )报错:

Exception in thread "main" Java.NET.UnknownHostException: locathost
at java.Net.PlainSocketImpl.connect(PlainSocketImpl.java:195)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at com.rabbitmq.client.impl.FrameHandlerFactory.create(FrameHandlerFactory.java:32)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:588)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:612)
at com.aaa.test.Send.main(Send.java:19)

2、如果写错端口PORT(如:factory.setPort(5678);) 报错:

Exception in thread "main" java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at com.rabbitmq.client.impl.FrameHandlerFactory.create(FrameHandlerFactory.java:32)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:588)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:612)
at com.aaa.test.Send.main(Send.java:19)

3、如果写错用户名或者密码,报错:

Exception in thread "main" com.rabbitmq.client.AuthenticationFailureException: ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. 
For details see the broker logfile.
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:338)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:590)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:612)
at com.aaa.test.Send.main(Send.java:19)

rabbitMQ Connection timed out的更多相关文章

  1. ssh启动报错:org.dom4j.DocumentException: Connection timed out: connect Nested exception: Connection timed out: connect

    ssh项目启动报错: org.dom4j.DocumentException: Connection timed out: connect Nested exception: Connection t ...

  2. weedfs getsockopt: connection timed out

    启动master weed master -ip 10.191.197.133 -mdir /namenode -ip.bind 10.191.197.133 I0809 16:53:51 7721 ...

  3. nginx 报错 upstream timed out (110: Connection timed out)解决方案

    nginx 作PHP的web接口服务器. 在线上发现时不时经常崩溃.504,导致接口访问无响应回复. 查看日志: [error] 11618#0: *324911 upstream timed out ...

  4. 压测 502 日志报错 upstream timed out (110: Connection timed out)

    环境介绍 服务器:centos6.5服务:nginx proxy 问题描述: 压测 开发同事 的开发环境项目没事,但是 线上机器 命中%50 ,大量502 php的某些页面打不开,页面提示gatewa ...

  5. hibernate3.0 org.dom4j.DocumentException: Connection timed out: connect Nested exception:

    hibernate3.0 org.dom4j.DocumentException: Connection timed out: connect Nested exception:   所报异常: 严重 ...

  6. nginx 报错 upstream timed out (110: Connection timed out)解决方案【转】

    转自 nginx 报错 upstream timed out (110: Connection timed out)解决方案 - 为程序员服务http://outofmemory.cn/code-sn ...

  7. 项目的ip地址更改,用git从远程提取代码出现错误,提示为 network error connection timed out

    昨天公司的ip进行了修改,在今天从远程提取代码的过程中提示network error connection timed out错误,从网上看了一下解决方法 1:打开项目文件夹,点击查看 2:勾选隐藏的 ...

  8. AndroidStudio升级后出现Refresh gradle project和connection timed out的原因和解决方法

    笔者发现现在升级AndroidStudio不需要FQ了,于是在看到了升级提醒后手贱点击了升级.可悲剧的一幕发生了, 正在写的一个项目从上到下密密麻麻的错误,看了一下提示要求升级Gradle 那就升级吧 ...

  9. 【LR11】Error -27796: Failed to connect to server"server:port": [10060] Connection timed out错误解决办法

      场景描述:被测系统是发布在远程服务器上的,假设IP是10.10.10.10,端口是8066,那么访问地址是http://10.10.10.10:8066/,在control机器上我设置了IP欺骗. ...

随机推荐

  1. javascript面向对象详解

    认识面向对象 1.面向对象中的概念 一切事物皆对象 对象具有封装和继承特性 信息隐藏 2.基本面向对象 3.函数构造器构造对象 深入了解面向对象 第一种书写格式 第二种书写格式

  2. .NET学习记录2

    前面回忆了一些C#基础语法,简单整理了一下笔记,要想深入研究的话,那就得找一本比较好的书了.接下来继续回忆C#语法知识. 方法 功能:用来复用代码的.当我们在一个程序 中反复的写了同样的代码,那么一般 ...

  3. paper 95:《模式识别和机器学习》资源

    Bishop的<模式识别和机器学习>是该领域的经典教材,本文搜罗了有关的教程和读书笔记,供对比学习之用,主要搜索的资源包括CSDN:http://download.csdn.net/sea ...

  4. python对json的操作总结

    Json简介:Json,全名 JavaScript Object Notation,是一种轻量级的数据交换格式.Json最广泛的应用是作为AJAX中web服务器和客户端的通讯的数据格式.现在也常用于h ...

  5. 机器学习实战-边学边读python代码(4)

    程序2-4 分类器针对约会网站的测试代码(4) def datingClassTest():hoRatio = 0.10 //将文件读入内存矩阵datingDataMat,datingLabels = ...

  6. UnicodeDecodeError: 'utf8' codec can't decode byte 0xce in position 47: invalid continuation byte

  7. LeetCode----263. Ugly Number(Java)

    package isUgly263; /* * Write a program to check whether a given number is an ugly number. Ugly numb ...

  8. Tomcat 发布war包提示war包超出大小修改

    error信息: java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$Size ...

  9. 【转】本地存储-localStroage/sessionStorage存储

    原文地址:[js学习笔记-103]----本地存储-localStroage/sessionStorage存储 客户端存储 l  WEB存储 web存储最初作为html5的一部分被定义成API形式,但 ...

  10. 游戏引擎PushButtonEngine简介

    PushButtonEngine是一个开源的模块化游戏引擎,你可以通过https://github.com/PushButtonLabs/PushButtonEngine得到其代码和相关文档.下面我将 ...