view spring-jms-playground/src/main/java/de/comline/jms/application/Application.java @ 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
children 4217059d40e8
line wrap: on
line source

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;
		}
	}
}