gstackoverflow
gstackoverflow

Reputation: 37034

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

I am reading the following article SPRING_BOOT_JMS_GETTING_STARTED

This example explains how to get started with emdedded ActiveMq message broker But I already have RabbitMq installed on my PC and I want to use this one.

First of all I enabled the jms rabbitMq plugin

enter image description here

But I don't see additional exchanges in the management console:

enter image description here

I expected to see it because of this answer

Honestly, I don't understand what should I do right now.

I have a code from Getting Started and I switched on the jms RabbitMq plugin.

Please advice me subsequent steps.

Small remark:

Garry answer works if I use following gradle dependencies:

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'
}

Upvotes: 2

Views: 947

Answers (1)

Gary Russell
Gary Russell

Reputation: 174554

The exchange won't show up until you actually use it. I just wrote a quick boot app and it worked fine for me...

@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();
    }

}

Result:

bar

Upvotes: 1

Related Questions