gpt4 book ai didi

java - 带有 ActiveMQ 的 Spring JMS

转载 作者:搜寻专家 更新时间:2023-11-01 03:37:25 25 4
gpt4 key购买 nike

我在尝试向我的队列发帖时遇到以下错误:

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

当我直接在浏览器中输入 URL 时,我可以毫无问题地访问管理屏幕。

有什么想法吗?

这是我的配置:

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

}

运行.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);
}
}

谢谢!

最佳答案

默认情况下,ActiveMQ 使用 TCP transport在端口 61616 上,这是 brokerURL 应该指向的内容...

<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616" />
</bean>

关于java - 带有 ActiveMQ 的 Spring JMS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26614807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com