无法使用@JmsListener连接到远程队列

时间:2019-02-27 14:58:42

标签: spring-boot jms

我需要创建一个JMS侦听器(首选注释)以从远程队列接收消息。我从{.3}的spring.io教程开始。

这是一个只有应用程序文件的简单示例:

  s.subspec 'SwiftStdlib' do |sp|
    sp.source_files  = 'Sources/Extensions/SwiftStdlib/*.swift'
  end

和接收者:

@SpringBootApplication
@EnableJms
public class Application {

@Bean
public JmsListenerContainerFactory<?> myFactory(ConnectionFactory connectionFactory,
                                                DefaultJmsListenerContainerFactoryConfigurer configurer) {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    // This provides all boot's default to this factory, including the message converter
    configurer.configure(factory, connectionFactory);
    // You could still override some of Boot's default if necessary.
    return factory;
}

@Bean // Serialize message content to json using TextMessage
public MessageConverter jacksonJmsMessageConverter() {
    MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
    converter.setTargetType(MessageType.TEXT);
    converter.setTypeIdPropertyName("_type");
    return converter;
}

public static void main(String[] args) {
    // Launch the application
    ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);

    JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);

    System.out.println("Sending a message.");
    jmsTemplate.convertAndSend("mailbox", "someString");
}

}

这很好。下一步是使侦听器适应从远程队列接收的内容。我们使用的是Tibco Jms,我用TibjmsConnectionFactory替换了bean中的Connection Factory,并提供了URL,用户名,密码和客户端ID。在@JmsListener的目标字段中,我放置了远程队列的queueName,还提供了containerFactory bean。但是,当我运行该应用程序时,出现以下错误:

@Component
public class Receiver {

@JmsListener(destination = "mailbox", containerFactory = "myFactory")
public void receiveMessage(String message) {
    System.out.println("Received message:" + message);
}

}

如果我注释掉侦听器,我不会出错

我看不到我想念的东西

0 个答案:

没有答案