Merge pull request #260 from bsinno/feature_allow_to_use_other_exception_handler
Allow to set error handler or take default one
This commit is contained in:
@@ -10,8 +10,12 @@ package org.eclipse.hawkbit.autoconfigure.amqp;
|
||||
|
||||
import org.eclipse.hawkbit.amqp.AmqpConfiguration;
|
||||
import org.eclipse.hawkbit.amqp.annotation.EnableAmqp;
|
||||
import org.springframework.amqp.rabbit.listener.ConditionalRejectingErrorHandler;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.ErrorHandler;
|
||||
|
||||
/**
|
||||
* The amqp autoconfiguration.
|
||||
@@ -24,4 +28,15 @@ import org.springframework.context.annotation.Configuration;
|
||||
@EnableAmqp
|
||||
public class AmqpAutoConfiguration {
|
||||
|
||||
/**
|
||||
* Create default error handler bean.
|
||||
*
|
||||
* @return the default error handler bean
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ErrorHandler errorHandler() {
|
||||
return new ConditionalRejectingErrorHandler();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,7 +37,8 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.retry.backoff.ExponentialBackOffPolicy;
|
||||
import org.springframework.retry.support.RetryTemplate;;
|
||||
import org.springframework.retry.support.RetryTemplate;
|
||||
import org.springframework.util.ErrorHandler;
|
||||
|
||||
/**
|
||||
* The spring AMQP configuration which is enabled by using the profile
|
||||
@@ -263,13 +264,16 @@ public class AmqpConfiguration {
|
||||
|
||||
/**
|
||||
* Returns the Listener factory.
|
||||
*
|
||||
*
|
||||
* @param errorHandler
|
||||
* the error hander
|
||||
* @return the {@link SimpleMessageListenerContainer} that gets used receive
|
||||
* AMQP messages
|
||||
*/
|
||||
@Bean(name = { "listenerContainerFactory" })
|
||||
public RabbitListenerContainerFactory<SimpleMessageListenerContainer> listenerContainerFactory() {
|
||||
return new ConfigurableRabbitListenerContainerFactory(amqpProperties, rabbitConnectionFactory);
|
||||
public RabbitListenerContainerFactory<SimpleMessageListenerContainer> listenerContainerFactory(
|
||||
final ErrorHandler errorHandler) {
|
||||
return new ConfigurableRabbitListenerContainerFactory(amqpProperties, rabbitConnectionFactory, errorHandler);
|
||||
}
|
||||
|
||||
private static Map<String, Object> getTTLMaxArgsAuthenticationQueue() {
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFacto
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory;
|
||||
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
|
||||
import org.springframework.util.ErrorHandler;
|
||||
|
||||
/**
|
||||
* {@link RabbitListenerContainerFactory} that can be configured through
|
||||
@@ -28,10 +29,13 @@ public class ConfigurableRabbitListenerContainerFactory extends SimpleRabbitList
|
||||
* for the container factory
|
||||
* @param amqpProperties
|
||||
* to configure the container factory
|
||||
* @param errorHandler
|
||||
* the error handler which should be use
|
||||
*/
|
||||
public ConfigurableRabbitListenerContainerFactory(final AmqpProperties amqpProperties,
|
||||
final ConnectionFactory rabbitConnectionFactory) {
|
||||
final ConnectionFactory rabbitConnectionFactory, final ErrorHandler errorHandler) {
|
||||
this.amqpProperties = amqpProperties;
|
||||
setErrorHandler(errorHandler);
|
||||
setDefaultRequeueRejected(true);
|
||||
setConnectionFactory(rabbitConnectionFactory);
|
||||
setMissingQueuesFatal(amqpProperties.isMissingQueuesFatal());
|
||||
|
||||
Reference in New Issue
Block a user