view spring-jms-playground/src/main/java/de/comline/jms/application/Application.java @ 19:fe6a57f7a2cf

Spring Cloud Config server
author Dirk Olmes <dirk.olmes@codedo.de>
date Thu, 17 Sep 2020 17:24:48 +0200
parents 8504317b9a09
children
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.cloud.sleuth.autoconfig.TraceAutoConfiguration;
import org.springframework.cloud.sleuth.instrument.messaging.ExposedSleuthJmsConfiguration;
import org.springframework.cloud.sleuth.instrument.messaging.TraceMessagingAutoConfiguration;
import org.springframework.cloud.sleuth.instrument.messaging.TraceSpringIntegrationAutoConfiguration;
import org.springframework.cloud.sleuth.log.SleuthLogAutoConfiguration;
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 final String AMQ_FACTORY_BEAN = "amqFactory";

	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}

	// @formatter:off
//	@EnableAutoConfiguration
//	@Import(QueueReceiver.class)
	@Configuration
	@Import({ SleuthLogAutoConfiguration.class, TraceAutoConfiguration.class, TraceMessagingAutoConfiguration.class, ExposedSleuthJmsConfiguration.class, TraceSpringIntegrationAutoConfiguration.class,
		ActiveMQAutoConfiguration.class, JmsAutoConfiguration.class,
		QueueReceiver.class })
	// @formatter:on
	public static class AppConfig {
		@Bean(name = AMQ_FACTORY_BEAN)
		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;
		}
	}
}