ActiveMQ 的 @SendTo 注释无提示地失败

2024-05-06

我试图使用 @SendTo 注释将 JMS 消息推送到 SpringBoot 应用程序中的独立 ActiveMQ 代理,但是执行完成时没有错误/异常,但消息未排队。相反,如果我使用 JmsTemplate (在代码中注释),消息将排队。使用@SendTo是否需要任何额外配置?我在这里做错了什么?

应用程序属性

spring.activemq.broker-url= tcp://localhost:61616
spring.activemq.user= admin
spring.activemq.password= admin
spring.activemq.pool.enabled= false

Spring引导应用程序

@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, 消息);

注意:这是一个解决方法。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ActiveMQ 的 @SendTo 注释无提示地失败 的相关文章

随机推荐