【问题标题】:How to start hello world jms app with spring boot and rabbit mq如何使用 spring boot 和 rabbitmq 启动 hello world js 应用程序
【发布时间】:2017-08-17 11:29:28
【问题描述】:

我正在阅读下面的文章SPRING_BOOT_JMS_GETTING_STARTED

此示例说明如何开始使用嵌入式 ActiveMq 消息代理 但我已经在我的电脑上安装了 RabbitMq,我想使用这个。

首先我启用了 jms rabbitMq 插件

但我在管理控制台中没有看到其他交换:

因为this answer所以我期待看到它

老实说,我不明白我现在应该做什么。

我有一个入门代码,我打开了 jms RabbitMq 插件。

请告诉我后续步骤。

小备注:

如果我使用以下 gradle 依赖项,Garry 答案有效:

dependencies {
    compile("org.springframework.boot:spring-boot-starter")
    compile group: 'org.springframework', name: 'spring-jms', version: '4.3.10.RELEASE'
    compile group: 'com.rabbitmq.jms', name: 'rabbitmq-jms', version: '1.7.0'
}

【问题讨论】:

    标签: java spring rabbitmq spring-jms


    【解决方案1】:

    在您实际使用之前,交换不会显示。我刚刚写了一个快速启动应用程序,它对我来说很好用......

    @SpringBootApplication
    public class RabbitJmsApplication implements CommandLineRunner {
    
        public static void main(String[] args) {
            SpringApplication.run(RabbitJmsApplication.class, args);
        }
    
        @Autowired
        private JmsTemplate template;
    
        @Override
        public void run(String... arg0) throws Exception {
            template.convertAndSend("foo", "bar");
            template.setReceiveTimeout(10_000);
            System.out.println(template.receiveAndConvert("foo"));
        }
    
        @Bean
        public RMQConnectionFactory connectionFactory() {
            return new RMQConnectionFactory();
        }
    
    }
    

    结果:

    bar
    

    【讨论】:

    • 工作正常! foo 队列是自动创建的
    • @Garry 我也想知道为什么示例不包含 connectionFactory bean 定义,但是对于 rabbitMq,spring 没有启动并说:
    • **pack.Application 中方法 myFactory 的参数 0 需要一个无法找到的“javax.jms.ConnectionFactory”类型的 bean。 - 没有加载 Bean 方法“connectionFactory”,因为 AnyNestedCondition 0 匹配 2 没有; JndiConnectionFactoryAutoConfiguration.JndiOrPropertyCondition.Property @ConditionalOnProperty (spring.jms.jndi-name) 上的 NestedCondition 未找到属性“jndi-name”; JndiConnectionFactoryAutoConfiguration.JndiOrPropertyCondition.Jndi 上的 NestedCondition (ad)ConditionalOnJndi JNDI 环境不可用**
    • 不要在 cmets 中放这样的东西;它不可读;改为编辑问题。该示例使用 spring-boot-starter-activemq 自动配置 ActiveMQ 的连接工厂。您正在使用需要 JNDI 提供程序的 JNDI 自动配置; rabbitmq 不提供;您指出的另一个答案使用fscontext JNDI 提供程序。我认为 JNDI 在这种环境下太过分了,所以我直接将连接工厂声明为 @Bean。
    • @Garry,感谢您的回答。我会在以后的帖子中听从你的建议。你能澄清一下哪个代码行导致使用 JNDI 自动配置吗?
    猜你喜欢
    • 2018-02-02
    • 2014-10-31
    • 2017-06-30
    • 1970-01-01
    • 2020-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多