【发布时间】:2019-05-28 18:48:03
【问题描述】:
我编写了一个 Spring Boot 应用程序,旨在推送和使用来自 JBoss Wildfly 10 ActiveMQ Artemis 的消息(注意:不是 Apache ActiveMQ 5.x)。我正在通过 Spring Tool Suite 运行此代码。
我还在本地系统(8080 端口)上设置了 JBoss Wildfly 10,并在 standalone-full.xml 配置文件中运行了相同的配置,以便在 Wildfly 的消息传递子系统中创建一个名为 TestQ 的队列。
接下来我在 Spring Boot 代码中使用 JMSTemplate 来推送和消费上述队列中的消息,application.properties 中包含以下内容:
spring.activemq.username=admin
spring.activemq.username=admin
spring.activemq.broker-url=http://localhost:8080
但是,我在运行代码时收到 Could not send message 错误。
您能否建议需要进行哪些更改?
我的基本目标是使用 Spring Boot 从这个外部队列推送和消费消息。
我在网上尝试了替代方案,但我得到的每个示例都是针对 Apache ActiveMQ 而不是 ActiveMQ Artemis 嵌入到 JBoss Wildfly 中,这是必需的。
我有以下 2 个课程:
1.
@SpringBootApplication
@EnableJms
public class App {
@Bean
public JmsListenerContainerFactory<?> myFactory(ConnectionFactory connectionFactory,
DefaultJmsListenerContainerFactoryConfigurer configurer) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
configurer.configure(factory, connectionFactory);
return factory;
}
public static void main(String[] args) {
// Launch the application
ConfigurableApplicationContext context = SpringApplication.run(App.class, args);
JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
System.out.println("Sending a JMS message.");
jmsTemplate.convertAndSend("sampleQueue", "Hello world!");
}
}
2.
@Component
public class ReceiveMessage {
@JmsListener(destination = "sampleQueue")
public void receiveMessage(String msg) {
System.out.println("Received :" + msg);
}
}
【问题讨论】:
-
强烈建议:将
org.apache.activemq.artemis日志设置为 DEBUG(在客户端和服务器上,如果不同的主机/不同的 WildFly 应用程序),回收应用程序服务器,并重新运行一些端到端测试.这可能是确定 1)谁失败以及 2)究竟是什么失败的最快/最有效的方法 -
我在上面提到了activemq broker url。对于独立的wildfly来说这似乎可以吗?
标签: spring-boot jboss-eap-7 activemq-artemis