I developed a spring boot application which send and listen message in Activemq using JMS, but while running application, JMS is not getting started by spring boot
This is mainclass, Application.java
@SpringBootApplication
@EnableJms
public class Main {
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
}
Configuration class: Config.java
@Configuration
public class Config {
@Bean
public Queue queue() {
return new ActiveMQQueue("inmemory.queue");
}
@Bean
public JmsTemplate jmsTemplate() {
return new JmsTemplate(activeMQConnectionFactory());
}
}
Listener class is used to listen to the queue: Listener.java
@Component
public class Listener {
@JmsListener(destination = "inmemory.queue")
public void listener(String message) {
System.out.println("message received" + message);
}
}
Producer class is used to send message to queue from controller: Producer.java
@RestController
public class Producer {
@Autowired
Queue queue;
@Autowired
JmsTemplate jmstemplate;
@RequestMapping(method = RequestMethod.GET, path = "/test3/{message}")
public String test3(@PathVariable String message) {
jmstemplate.convertAndSend(queue, message);
return "teste3" + message;
}
}
application.properties
spring.activemq.in-memory=true
spring.activemq.pool.enabled=false
server.port=8081
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-broker</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>5.1.4.RELEASE</version>
</dependency>
</dependencies>
</project>
This is a screenshot of application starting without starting JMS