Spring JMS with ActiveMQ
When trying to send a message to my queue, the following error occurs:
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: http://localhost:8161. Reason: java.io.IOException: Failed to perform GET on: http://localhost:8161 as response was: Not Found
at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:316)
at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:169)
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:496)
at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:568)
at org.springframework.jms.core.JmsTemplate.convertAndSend(JmsTemplate.java:657)
at org.springframework.jms.core.JmsTemplate.convertAndSend(JmsTemplate.java:648)
at com.spring.tutorials.amq.MessageSender.send(MessageSender.java:14)
at com.spring.tutorials.amq.Run.main(Run.java:24)
Caused by: javax.jms.JMSException: Could not connect to broker URL: http://localhost:8161. Reason: java.io.IOException: Failed to perform GET on: http://localhost:8161 as response was: Not Found
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:36)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:358)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:303)
at org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:243)
at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:180)
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:483)
... 5 more
Caused by: java.io.IOException: Failed to perform GET on: http://localhost:8161 as response was: Not Found
at org.apache.activemq.transport.http.HttpClientTransport.doStart(HttpClientTransport.java:279)
at org.apache.activemq.util.ServiceSupport.start(ServiceSupport.java:55)
at org.apache.activemq.transport.AbstractInactivityMonitor.start(AbstractInactivityMonitor.java:138)
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:338)
... 9 more
I can access the admin screen without any problem when entering the url directly in the browser.
Any ideas?
Here is my config:
active-mq-context.xml
<!-- Connection Factory Definition -->
<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="http://localhost:8161" />
</bean>
<!-- Destination Definition -->
<bean id="destination" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="MyTestQueue" />
</bean>
<!-- JMS Template Definition -->
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory" />
<property name="defaultDestination" ref="destination" />
</bean>
<!-- Message Sender Definition -->
<bean id="messageSender" class="com.spring.tutorials.amq.MessageSender">
<property name="jmsTemplate" ref="jmsTemplate" />
</bean>
MessageSender.java
package com.spring.tutorials.amq;
import org.springframework.jms.core.JmsTemplate;
public class MessageSender {
private JmsTemplate jmsTemplate;
public void setJmsTemplate(JmsTemplate jmsTemplate) {
this.jmsTemplate = jmsTemplate;
}
public void send(final Object Object) {
jmsTemplate.convertAndSend(Object);
}
}
Run.java
package com.spring.tutorials.amq;
import java.util.HashMap;
import java.util.Map;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Run {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("active-mq-context.xml");
MessageSender messageSender = (MessageSender) context.getBean("messageSender");
Map<String,String> message = new HashMap<String,String>();
message.put("message1", "Hello");
message.put("message2", "World");
messageSender.send(message);
}
}
Thank!
+3
source to share
1 answer
by default ActiveMQ uses TCP transport on port 61616, this is what the marketer should tell the URL ...
<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616" />
</bean>
+1
source to share