我试图将简单的消息发送到一个主题,从发件人 Spring应用程序到一个接收器 Spring应用程序。但我一直有两个例外。
第一个异常发生在应用程序中:
javax.jms.JMSException: Failed to create session factory
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:882) ~[artemis-jms-client-2.19.1.jar:2.19.1]
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:299) ~[artemis-jms-client-2.19.1.jar:2.19.1]
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:294) ~[artemis-jms-client-2.19.1.jar:2.19.1]
at org.springframework.jms.connection.SingleConnectionFactory.doCreateConnection(SingleConnectionFactory.java:410) ~[spring-jms-5.3.18.jar:5.3.18]
at org.springframework.jms.connection.SingleConnectionFactory.initConnection(SingleConnectionFactory.java:350) ~[spring-jms-5.3.18.jar:5.3.18]
at org.springframework.jms.connection.SingleConnectionFactory.getConnection(SingleConnectionFactory.java:328) ~[spring-jms-5.3.18.jar:5.3.18]
at org.springframework.jms.connection.SingleConnectionFactory.createConnection(SingleConnectionFactory.java:243) ~[spring-jms-5.3.18.jar:5.3.18]
at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:196) ~[spring-jms-5.3.18.jar:5.3.18]几秒钟后,发件人应用程序中出现以下异常:
org.apache.activemq.artemis.api.core.ActiveMQConnectionTimedOutException: AMQ219013: Timed out waiting to receive cluster topology. Group:null
at org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:748) ~[artemis-core-client-2.19.1.jar:2.19.1]
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:880) ~[artemis-jms-client-2.19.1.jar:2.19.1]
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:299) ~[artemis-jms-client-2.19.1.jar:2.19.1]
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:294) ~[artemis-jms-client-2.19.1.jar:2.19.1]
at org.springframework.jms.connection.SingleConnectionFactory.doCreateConnection(SingleConnectionFactory.java:410) ~[spring-jms-5.3.18.jar:5.3.18]
at org.springframework.jms.connection.SingleConnectionFactory.initConnection(SingleConnectionFactory.java:350) ~[spring-jms-5.3.18.jar:5.3.18]
at org.springframework.jms.connection.SingleConnectionFactory.getConnection(SingleConnectionFactory.java:328) ~[spring-jms-5.3.18.jar:5.3.18]
at org.springframework.jms.connection.SingleConnectionFactory.createConnection(SingleConnectionFactory.java:243) ~[spring-jms-5.3.18.jar:5.3.18]我正在跟踪Spring微服务上的一个Udemy 课程,其中第13章和第14章专门讨论JMS消息传递,因此,除了Spring的版本之外,我还有几乎相同的配置,我的配置是2.6.6,指导员的配置是2.1.x或类似的。我必须保留2.6.6因为我的项目中还有其他的东西。
我通过Docker成功地启动了Active MQ服务器,如下所示:
C:\Users\Miljan>docker run -it --rm -p 8161:8161 -p 61616:61616 vromero/activemq-artemis在运行映像之前,我必须下载图像,我可以看到服务器正在运行:

此外,我还可以登录到控制台(用户名:artemis;密码:simetraehcapa;):

发件人应用程序中的其他配置:
@EnableAsync
@EnableScheduling
@Configuration
public class AsyncConfig {
public static final String EXECUTOR = "SchedulerExecutor";
@Bean(name = EXECUTOR)
public Executor asyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(2);
executor.setMaxPoolSize(2);
executor.setQueueCapacity(50);
executor.setThreadNamePrefix(EXECUTOR + "-");
executor.initialize();
return executor;
}
}和
@Configuration
public class JmsConfig {
public static final String QUEUE = "queue";
@Bean // Serialize message content to json using TextMessage
public MessageConverter jacksonJmsMessageConverter(ObjectMapper objectMapper) {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
converter.setTargetType(MessageType.TEXT);
converter.setTypeIdPropertyName("_type");
converter.setObjectMapper(objectMapper);
return converter;
}
}和
spring.artemis.mode=native
spring.artemis.host=localhost
spring.artemis.port=8161
spring.artemis.user=artemis
spring.artemis.password=simetraehcapa最后,我是如何通过简单的GET请求(http://localhost:8080/send)发送消息的:
@GetMapping("/send")
public void sendMessage(){
Student s = new Student("MIKE");
this.jmsTemplate.convertAndSend(JmsConfig.QUEUE, s);
}和听者班:
@Component
@EnableJms
public class Listener {
@Autowired
private JmsTemplate jmsTemplate;
@JmsListener(destination = "queue")
public void listen(Student student){
System.out.println(student);
}
}所以我的问题是:
发布于 2022-05-14 19:26:29
我认为问题在于您的配置中的这一行:
spring.artemis.port=8161这指向ActiveMQ Artemis中嵌入式web服务器使用的HTTP端口。这不适合JMS客户端。你应该使用:
spring.artemis.port=61616https://stackoverflow.com/questions/72241890
复制相似问题