22

I am trying to use activemq in my application, but keep getting an error when I try and connect to 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. 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:

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?

Pritam Banerjee
  • 17,953
  • 10
  • 93
  • 108
Biscuit128
  • 5,218
  • 22
  • 89
  • 149
  • Um, it's telling you exactly what the problem is. `Usage:` isn't a suggestion. `activemq start` – Brian Roach Oct 29 '12 at 20:07
  • 1
    @BrianRoach I think the OP is presenting the usage from his mac os machine, the issue is on windows. – dan Oct 29 '12 at 20:08
  • @dan - He's trying to start activemq on his mac. He's not doing so and ignoring the message that tells him how. And since he hasn't started it, his application can't connect to it. – Brian Roach Oct 29 '12 at 20:09
  • i am a new mac user and much more comfortable with windows so im not sure exactly how it should be started – Biscuit128 Oct 29 '12 at 20:12
  • @SkyR - Read my first comment. And the `Usage:` message you received when you didn't give it an option. You have to pass `start` to it. – Brian Roach Oct 29 '12 at 20:13
  • ok so rather than double clicking the file i need to run it from the command line. ok let me try that – Biscuit128 Oct 29 '12 at 20:14
  • Heh ... you didn't mention the double-clicking part. Makes more sense now. – Brian Roach Oct 29 '12 at 20:15

3 Answers3

19

Your application is not able to connect to activemq. Check that your activemq is running and listening on localhost 61616.

You can try using: netstat -a to check if the activemq process has started. Or try check if you can access your actvemq using admin page: localhost:8161/admin/queues.jsp

On mac you will start your activemq using:

$ACTMQ_HOME/bin/activemq start 

Or if your config file (activemq.xml ) if located in another location you can use:

$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

dan
  • 13,132
  • 3
  • 38
  • 49
  • sorry to be a royal pain in the ass but i am getting No such file or directory even though i no the file is there – Biscuit128 Oct 29 '12 at 20:28
  • @SkyR Just now I noticed that your executable is under: `bin/macosx/activemq`. I updated my answer. – dan Oct 29 '12 at 20:29
  • lol thanks. thats made a slight difference. it suggests its running now but i still get the same exception (null):macosx rickilambert$ ./activemq start Starting ActiveMQ Broker... – Biscuit128 Oct 29 '12 at 20:33
  • @SkyR you can check in logs if the server is started. Also you can check if the server is started using the URL that I provided in my answer. Usually it taking a second or two to start, after issuing your start command. – dan Oct 29 '12 at 20:35
5

I encountered a similar problem when I was using the below to obtain connection factory 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

Kranthi
  • 109
  • 2
  • 7
0

I had also similar problem. In my case brokerUrl was not configured properly. 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");
Narayan Yerrabachu
  • 1,714
  • 1
  • 19
  • 31
  • I don't understand how this works. The reference documentation says this: "If the broker is present, an embedded broker is automatically started and configured (provided no broker URL is specified through configuration)" But you've specified a broker URL, so this would mean that Spring Boot would not launch an embedded broker. Are you using an embedded broker? – MiguelMunoz Sep 15 '18 at 20:31
  • read this document : https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-messaging.html – Narayan Yerrabachu Sep 16 '18 at 02:53
  • In my case I want to run my created Instance. Thats why I provided URL. spring.activemq.broker-url not provided then spring boot instantiate default one. – Narayan Yerrabachu Sep 16 '18 at 03:02
  • Check 1) Activemq started or not with the following command : netstat -a – Narayan Yerrabachu Sep 16 '18 at 03:12