问题描述
我正在尝试使用@SendTo注释将JMS消息推送到SpringBoot应用程序中的独立ActiveMQ代理,但是执行完成没有错误/异常,但是消息未排队.相反,如果我使用JmsTemplate(在代码中注释),则消息将排队.使用@SendTo是否需要任何其他配置.我在这里做错什么了?
I am trying to push a JMS message to a standalone ActiveMQ broker in a SpringBoot Application using @SendTo annotiation, however the execution completes without error/exception but the message is not queued. Instead if I use JmsTemplate (commented in code), the message is queued. Is there any additional configuration required for using @SendTo. What am I doing wrong here?
application.properties
spring.activemq.broker-url= tcp://localhost:61616
spring.activemq.user= admin
spring.activemq.password= admin
spring.activemq.pool.enabled= false
Spring Boot应用程序
@SpringBootApplication
public class MyCustomRouterApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(MyCustomRouterApplication.class, args);
}
}
服务方法
@Service
public class NotificationServiceImpl implements NotificationService {
//@Autowired
//JmsTemplate jmsTemplate;
@Override
@SendTo("inboundSyncQueue")
public Map<String, Object> enqueueExchangeNotification(ExchangeNotification notification, String tenantId) throws RuntimeException {
Map<String, Object> jmsMessage = new HashMap<String, Object>();
jmsMessage.put("tenantId", tenantId);
jmsMessage.put("source", ExternalNotificationSource.EXCHANGE);
jmsMessage.put("payload", notification);
//jmsTemplate.convertAndSend("inboundSyncQueue", notification);
return jmsMessage;
}
}
maven pom
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<!-- Required for ActiveMQ JMS Consumer -->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-camel</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<!-- Required for Guava In-memory Cache -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>21.0</version>
</dependency>
<!-- Required for String Utilities -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-messaging</artifactId>
</dependency>
</dependencies>
推荐答案
我在生产者上使用了jmsTemplate而不是@sendTo.下面是一种方法.jmsTemplate.convertAndSend(destinationQueue,消息);
Instead of @sendTo , I used jmsTemplate at producer. Below is a method.jmsTemplate.convertAndSend(destinationQueue, message);
注意:这是一种解决方法.
Note: It's a workaround.
这篇关于@SendTo注释对于ActiveMQ静默失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!