简体   繁体   English

ActiveMQ连接被拒绝

[英]ActiveMQ connection refused

I am trying to use activemq in my application, but keep getting an error when I try and connect to localhost : 我试图在我的应用程序中使用activemq ,但在尝试连接到localhost时仍然出现错误:

log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" org.springframework.jms.UncategorizedJmsException: Uncategorized exception occured during JMS processing; nested exception is javax.jms.JMSException: Could not connect to broker URL: tcp://localhost:61616. Reason: java.net.ConnectException: Connection refused
    at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:316)
    at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:168)
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:469)
    at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:534)
    at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:526)
    at sender.MessageSender.sendMessage(MessageSender.java:16)
    at sender.SenderMain.main(SenderMain.java:13)
Caused by: javax.jms.JMSException: Could not connect to broker URL: tcp://localhost:61616. Reason: java.net.ConnectException: Connection refused
    at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:35)
    at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:293)
    at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:238)
    at org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:184)
    at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:184)
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:456)
    ... 4 more
Caused by: java.net.ConnectException: Connection refused
    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:432)
    at java.net.Socket.connect(Socket.java:529)
    at org.apache.activemq.transport.tcp.TcpTransport.connect(TcpTransport.java:504)
    at org.apache.activemq.transport.tcp.TcpTransport.doStart(TcpTransport.java:467)
    at org.apache.activemq.util.ServiceSupport.start(ServiceSupport.java:55)
    at org.apache.activemq.transport.AbstractInactivityMonitor.start(AbstractInactivityMonitor.java:132)
    at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:58)
    at org.apache.activemq.transport.WireFormatNegotiator.start(WireFormatNegotiator.java:72)
    at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:58)
    at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:58)
    at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:273)
    ... 8 more

There is a file that should be run to start it up (active mq) and this is a .bat file on windows machines. 应该运行一个文件来启动它(活动mq),这是Windows机器上的.bat文件。 When you run it then it starts and you leave it running in the command prompt. 当你运行它然后它启动并让你在命令提示符下运行它。

At home I have a mac and using the mac equivalent the terminal just prints: 在家里我有一个mac并使用mac等效终端打印:

Last login: Mon Oct 29 19:57:15 on ttys000
(null):~ rickilambert$ /Users/rickilambert/Downloads/apache-activemq-5.7.0/bin/macosx/activemq ; exit;
Usage: /Users/rickilambert/Downloads/apache-activemq-5.7.0/bin/macosx/activemq { console | start | stop | restart | status | dump }
logout

[Process completed]

Can anyone please help me to get this thing up and running? 任何人都可以帮助我让这个东西运行起来吗?

Your application is not able to connect to activemq. 您的应用程序无法连接到activemq。 Check that your activemq is running and listening on localhost 61616. 检查您的activemq是否正在运行并正在侦听localhost 61616。

You can try using: netstat -a to check if the activemq process has started. 您可以尝试使用: netstat -a来检查activemq进程是否已启动。 Or try check if you can access your actvemq using admin page: localhost:8161/admin/queues.jsp 或者尝试使用管理页面检查您是否可以访问actvemq:localhost:8161 / admin / queues.jsp

On mac you will start your activemq using: 在Mac上,您将使用以下命令启动您的activemq:

$ACTMQ_HOME/bin/activemq start 

Or if your config file (activemq.xml ) if located in another location you can use: 或者,如果您的配置文件(activemq.xml)位于另一个位置,您可以使用:

$ACTMQ_HOME/bin/activemq start xbean:file:${location_of_your_config_file}

In your case the executable is under: bin/macosx/activemq so you need to use: $ACTMQ_HOME/bin/macosx/activemq start 在您的情况下,可执行文件位于: bin/macosx/activemq因此您需要使用: $ACTMQ_HOME/bin/macosx/activemq start

I encountered a similar problem when I was using the below to obtain connection factory ConnectionFactory factory = new 当我使用下面的连接工厂ConnectionFactory factory = new时,我遇到了类似的问题
ActiveMQConnectionFactory("admin","admin","tcp://:61616");

Its resolved when I changed it to the below 当我将其更改为下面时,它已解决

ConnectionFactory factory = new ActiveMQConnectionFactory("tcp://:61616");

The below then showed that my Q size was increasing.. http://:8161/admin/queues.jsp 下面显示我的Q大小正在增加.. http://:8161/admin/queues.jsp

I had also similar problem. 我也有类似的问题。 In my case brokerUrl was not configured properly. 在我的情况下,brokerUrl配置不正确。 So that's way I received following Error: 所以这是我收到以下错误的方式:

Cause: Error While attempting to add new Connection to the pool: nested exception is javax.jms.JMSException: Could not connect to broker URL : tcp://localhost:61616. Reason: java.net.ConnectException: Connection refused

& I resolved it following way. 我按照以下方式解决了问题。

   ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();

  connectionFactory.setBrokerURL("tcp://hostname:61616");
  connectionFactory.setUserName("admin");
  connectionFactory.setPassword("admin");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM