21

我正在尝试在我的应用程序中使用,但是当我尝试连接到localhostactivemq时不断收到错误消息:

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

应该运行一个文件来启动它(活动 mq),这是.batWindows 机器上的一个文件。当您运行它时,它会启动,并让它在命令提示符下运行。

在家里,我有一台 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]

任何人都可以帮我启动并运行这个东西吗?

4

3 回答 3

18

您的应用程序无法连接到 activemq。检查您的 activemq 是否正在运行并在 localhost 61616 上侦听。

您可以尝试使用:netstat -a来检查 activemq 进程是否已启动。或者尝试检查您是否可以使用管理页面访问您的 actvemq:localhost:8161/admin/queues.jsp

在 mac 上,您将使用以下命令启动您的 activemq:

$ACTMQ_HOME/bin/activemq start 

或者,如果您的配置文件(activemq.xml)位于另一个位置,您可以使用:

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

在您的情况下,可执行文件位于:bin/macosx/activemq所以您需要使用:$ACTMQ_HOME/bin/macosx/activemq start

于 2012-10-29T20:07:01.027 回答
5

我在使用以下获取连接工厂 ConnectionFactory factory = new 时遇到了类似的问题
ActiveMQConnectionFactory("admin","admin","tcp://:61616");

当我将其更改为以下时,它已解决

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

下面显示我的 Q 尺寸正在增加.. http://:8161/admin/queues.jsp

于 2014-11-30T20:51:23.580 回答
0

我也有类似的问题。在我的情况下,brokerUrl 配置不正确。这就是我收到以下错误的方式:

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

&我按照以下方式解决了它。

   ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();

  connectionFactory.setBrokerURL("tcp://hostname:61616");
  connectionFactory.setUserName("admin");
  connectionFactory.setPassword("admin");
于 2017-11-27T13:51:57.117 回答