@SendTo Annotation无声地为ActiveMQ失败

时间:2018-05-29 08:36:04

标签: java spring spring-boot jms activemq

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

application.properties

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

Spring Boot Application

@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>

1 个答案:

答案 0 :(得分:0)

而不是@sendTo,我在制作人处使用了jmsTemplate。以下是一种方法。 jmsTemplate.convertAndSend(destinationQueue,message);

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