An open API service indexing awesome lists of open source software.

https://github.com/colinbut/activemq-spring-example

ActiveMQ example with Spring
https://github.com/colinbut/activemq-spring-example

activemq activemq-broker-instance annotations jms spring spring-boot xml-configuration

Last synced: about 1 month ago
JSON representation

ActiveMQ example with Spring

Awesome Lists containing this project

README

          

# ActiveMQ - Spring Example

This project repository demonstrates ways to use ActiveMQ with the Spring framework.

Spring provides JMS abstractions for working with messaging. All the low level JMS implementations by ActiveMQ is hidden away by Spring.

ActiveMQ implements JMS.

Just use `JmsTemplate`

### Spring XML Configuration

This sub project shows how to simply integrate ActiveMQ with Spring. Uses the traditional XML configuration approach.

need to define an application context file:

```

















```

need to start up the ActiveMQ broker instance.

### Spring XML Configuration with Annotations (component scanning)

also need to define a application context file.

```















```

And simply annotate the beans:

```
@Service
public class MessageSender {

@Autowired
private JmsTemplate jmsTemplate;
```

need to start up the ActiveMQ broker instance.

### Spring Boot - Spring JMS - Java Configuration

This sub project shows Bootstrapping spring application that uses ActiveMQ with Spring Boot.

Spring Boot starts up an embedded ActiveMQ broker instance.

No XML configuration required.

Just using Spring Java Configuration. All configuration is done using Java code. Very simple and clean.

```
@SpringBootApplication
@EnableJms
public class Application {

@Bean
public JmsListenerContainerFactory> myFactory(ConnectionFactory connectionFactory,
DefaultJmsListenerContainerFactoryConfigurer defaultJmsListenerContainerFactoryConfigurer) {
DefaultJmsListenerContainerFactory defaultJmsListenerContainerFactory = new DefaultJmsListenerContainerFactory();
defaultJmsListenerContainerFactoryConfigurer.configure(defaultJmsListenerContainerFactory, connectionFactory);
return defaultJmsListenerContainerFactory;
}

@Bean
public MessageConverter jacksonJmsMessageConverter() {
//....
}

```

The consumer:

```
@Component
public class Receiver {

@JmsListener(destination = "destination", containerFactory = "myFactory")
public void receiveMessage(Email email) {
//....
}
}
```

For Prodcuer:

just simply get the `JmsTemplate` and use one of its send methods