# HG changeset patch # User Dirk Olmes # Date 1599720260 -7200 # Node ID ad77abd85976a7cc8f8bfd3166b739e002440bfe # Parent 4594ff529ab1260c50496a4375da5cc08760b3dd playground for spring boot JMS handling diff -r 4594ff529ab1 -r ad77abd85976 spring-jms-playground/pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spring-jms-playground/pom.xml Thu Sep 10 08:44:20 2020 +0200 @@ -0,0 +1,59 @@ + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.1.16.RELEASE + + + de.comline + spring-jms-playground + 0.0.1-SNAPSHOT + Spring boot JMS playground + + + 1.8 + 1.8 + ${jdk.version.source} + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + true + ${jdk.version.source} + ${jdk.version.target} + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + + org.springframework.boot + spring-boot-starter-activemq + + + + org.junit.jupiter + junit-jupiter + 5.6.2 + test + + + org.hamcrest + hamcrest + 2.2 + test + + + \ No newline at end of file diff -r 4594ff529ab1 -r ad77abd85976 spring-jms-playground/src/main/java/de/comline/jms/application/Application.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spring-jms-playground/src/main/java/de/comline/jms/application/Application.java Thu Sep 10 08:44:20 2020 +0200 @@ -0,0 +1,43 @@ +package de.comline.jms.application; + +import javax.jms.ConnectionFactory; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.jms.DefaultJmsListenerContainerFactoryConfigurer; +import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration; +import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.jms.config.DefaultJmsListenerContainerFactory; +import org.springframework.jms.config.JmsListenerContainerFactory; + +import de.comline.jms.application.Application.AppConfig; +import de.comline.jms.receiver.QueueReceiver; + +@Import(AppConfig.class) +public class Application { + private static final Logger LOG = LoggerFactory.getLogger(Application.class); + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + + @Configuration + @Import({ ActiveMQAutoConfiguration.class, JmsAutoConfiguration.class, QueueReceiver.class }) + public static class AppConfig { + @Bean(name = "amqFactory") + public JmsListenerContainerFactory configureJmsListenerFactory(ConnectionFactory connectionFactory, DefaultJmsListenerContainerFactoryConfigurer configurer) { + DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory(); + + factory.setErrorHandler(exception -> { + LOG.error("An error has occurred in JMS", exception); + }); + + configurer.configure(factory, connectionFactory); + return factory; + } + } +} diff -r 4594ff529ab1 -r ad77abd85976 spring-jms-playground/src/main/java/de/comline/jms/receiver/QueueReceiver.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spring-jms-playground/src/main/java/de/comline/jms/receiver/QueueReceiver.java Thu Sep 10 08:44:20 2020 +0200 @@ -0,0 +1,16 @@ +package de.comline.jms.receiver; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.jms.annotation.JmsListener; +import org.springframework.stereotype.Component; + +@Component +public class QueueReceiver { + private static final Logger LOG = LoggerFactory.getLogger(QueueReceiver.class); + + @JmsListener(destination = "input-queue", containerFactory = "amqFactory") + public void receive(String message) { + LOG.info("received {}", message); + } +} diff -r 4594ff529ab1 -r ad77abd85976 spring-jms-playground/src/main/resources/application.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spring-jms-playground/src/main/resources/application.properties Thu Sep 10 08:44:20 2020 +0200 @@ -0,0 +1,3 @@ +#spring.activemq.user=admin +#spring.activemq.password=admin +spring.activemq.broker-url=tcp://localhost:61616