changeset 15:ad77abd85976

playground for spring boot JMS handling
author Dirk Olmes <dirk.olmes@codedo.de>
date Thu, 10 Sep 2020 08:44:20 +0200
parents 4594ff529ab1
children 4217059d40e8
files spring-jms-playground/pom.xml spring-jms-playground/src/main/java/de/comline/jms/application/Application.java spring-jms-playground/src/main/java/de/comline/jms/receiver/QueueReceiver.java spring-jms-playground/src/main/resources/application.properties
diffstat 4 files changed, 121 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /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 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.springframework.boot</groupId>
+		<artifactId>spring-boot-starter-parent</artifactId>
+		<version>2.1.16.RELEASE</version>
+		<relativePath/>
+	</parent>
+	<groupId>de.comline</groupId>
+	<artifactId>spring-jms-playground</artifactId>
+	<version>0.0.1-SNAPSHOT</version>
+	<name>Spring boot JMS playground</name>
+
+	<properties>
+		<jdk.version.source>1.8</jdk.version.source>
+		<jdk.version.target>1.8</jdk.version.target>
+		<java.version>${jdk.version.source}</java.version>
+	</properties>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<verbose>true</verbose>
+					<source>${jdk.version.source}</source>
+					<target>${jdk.version.target}</target>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.springframework.boot</groupId>
+				<artifactId>spring-boot-maven-plugin</artifactId>
+			</plugin>
+		</plugins>
+	</build>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-activemq</artifactId>
+		</dependency>
+        
+		<dependency>
+			<groupId>org.junit.jupiter</groupId>
+			<artifactId>junit-jupiter</artifactId>
+			<version>5.6.2</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.hamcrest</groupId>
+			<artifactId>hamcrest</artifactId>
+			<version>2.2</version>
+			<scope>test</scope>
+		</dependency>
+	</dependencies>
+</project>
\ No newline at end of file
--- /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;
+		}
+	}
+}
--- /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);
+	}
+}
--- /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