如何使用 spring boot 和 rabbitmq 启动 hello world js 应用程序

How to start hello world jms app with spring boot and rabbit mq

我正在阅读以下文章SPRING_BOOT_JMS_GETTING_STARTED

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

首先我启用了jms rabbitMq插件

但是我在管理控制台中没有看到额外的交流:

因为

我希望看到它

老实说,我不知道我现在应该做什么。

我有一个入门代码,我打开了 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'
}

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

@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