I have two different apps for sender and receiver.
sender:
@SpringBootApplication
public class RabbitJmsApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(RabbitJmsApplication.class, args);
}
@Autowired
private JmsTemplate template;
@Autowired
private JmsTemplate topicTemplate;
@Override
public void run(String... arg0) throws Exception {
for (int i = 0; i < 10; i++) {
template.convertAndSend("my_queue", "msg_" + i);
Thread.sleep(100);
}
for (int i = 0; i < 10; i++) {
topicTemplate.convertAndSend("my_topic", "topic_msg_" + i);
Thread.sleep(100);
}
}
@Bean
public RMQConnectionFactory connectionFactory() {
return new RMQConnectionFactory();
}
@Bean
public JmsTemplate template() {
return new JmsTemplate(connectionFactory());
}
@Bean
public JmsTemplate topicTemplate() {
final JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory());
jmsTemplate.setPubSubDomain(true);
return jmsTemplate;
}
}
and receiver:
@Component
public class Listener {
@JmsListener(destination = "my_queue")
public void receive(String str){
System.out.println(str);
}
@JmsListener(destination = "my_topic")
public void receiveTopic(String str){
System.out.println(str);
}
}
I see
msg_1
msg_2
...
on the receiver but I don't see the topic messages.
What am I doing wrong?
P.S.
management console: