Search in sources :

Example 6 with MessagePublishingErrorHandler

use of org.springframework.integration.channel.MessagePublishingErrorHandler in project spring-integration by spring-projects.

the class PollerSpec method errorChannel.

/**
 * Specify a {@link MessageChannel} to use for sending error message in case
 * of polling failures.
 * @param errorChannel the {@link MessageChannel} to use.
 * @return the spec.
 * @see MessagePublishingErrorHandler
 */
public PollerSpec errorChannel(MessageChannel errorChannel) {
    MessagePublishingErrorHandler errorHandler = new MessagePublishingErrorHandler();
    errorHandler.setDefaultErrorChannel(errorChannel);
    this.componentsToRegister.put(errorHandler, null);
    return errorHandler(errorHandler);
}
Also used : MessagePublishingErrorHandler(org.springframework.integration.channel.MessagePublishingErrorHandler)

Example 7 with MessagePublishingErrorHandler

use of org.springframework.integration.channel.MessagePublishingErrorHandler in project spring-integration by spring-projects.

the class RedisQueueInboundGateway method onInit.

@Override
protected void onInit() throws Exception {
    super.onInit();
    if (!this.extractPayload) {
        Assert.notNull(this.serializer, "'serializer' has to be provided where 'extractPayload == false'.");
    }
    if (this.taskExecutor == null) {
        String beanName = this.getComponentName();
        this.taskExecutor = new SimpleAsyncTaskExecutor((beanName == null ? "" : beanName + "-") + this.getComponentType());
    }
    if (!(this.taskExecutor instanceof ErrorHandlingTaskExecutor) && this.getBeanFactory() != null) {
        MessagePublishingErrorHandler errorHandler = new MessagePublishingErrorHandler(new BeanFactoryChannelResolver(getBeanFactory()));
        errorHandler.setDefaultErrorChannel(getErrorChannel());
        this.taskExecutor = new ErrorHandlingTaskExecutor(this.taskExecutor, errorHandler);
    }
}
Also used : MessagePublishingErrorHandler(org.springframework.integration.channel.MessagePublishingErrorHandler) SimpleAsyncTaskExecutor(org.springframework.core.task.SimpleAsyncTaskExecutor) BeanFactoryChannelResolver(org.springframework.integration.support.channel.BeanFactoryChannelResolver) ErrorHandlingTaskExecutor(org.springframework.integration.util.ErrorHandlingTaskExecutor)

Example 8 with MessagePublishingErrorHandler

use of org.springframework.integration.channel.MessagePublishingErrorHandler in project spring-integration by spring-projects.

the class AbstractPollingEndpoint method onInit.

@Override
protected void onInit() {
    synchronized (this.initializationMonitor) {
        if (this.initialized) {
            return;
        }
        Assert.notNull(this.trigger, "Trigger is required");
        if (this.taskExecutor != null) {
            if (!(this.taskExecutor instanceof ErrorHandlingTaskExecutor)) {
                if (this.errorHandler == null) {
                    Assert.notNull(this.getBeanFactory(), "BeanFactory is required");
                    this.errorHandler = new MessagePublishingErrorHandler(new BeanFactoryChannelResolver(getBeanFactory()));
                    this.errorHandlerIsDefault = true;
                }
                this.taskExecutor = new ErrorHandlingTaskExecutor(this.taskExecutor, this.errorHandler);
            }
        }
        if (this.transactionSynchronizationFactory == null && this.adviceChain != null) {
            if (this.adviceChain.stream().anyMatch(TransactionInterceptor.class::isInstance)) {
                this.transactionSynchronizationFactory = new PassThroughTransactionSynchronizationFactory();
            }
        }
        this.initialized = true;
    }
    try {
        super.onInit();
    } catch (Exception e) {
        throw new BeanInitializationException("Cannot initialize: " + this, e);
    }
}
Also used : BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) TransactionInterceptor(org.springframework.transaction.interceptor.TransactionInterceptor) MessagePublishingErrorHandler(org.springframework.integration.channel.MessagePublishingErrorHandler) BeanFactoryChannelResolver(org.springframework.integration.support.channel.BeanFactoryChannelResolver) PassThroughTransactionSynchronizationFactory(org.springframework.integration.transaction.PassThroughTransactionSynchronizationFactory) MessagingException(org.springframework.messaging.MessagingException) BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) ErrorHandlingTaskExecutor(org.springframework.integration.util.ErrorHandlingTaskExecutor)

Example 9 with MessagePublishingErrorHandler

use of org.springframework.integration.channel.MessagePublishingErrorHandler in project spring-integration by spring-projects.

the class PollerSpec method errorChannel.

/**
 * Specify a bean name for the {@link MessageChannel} to use for sending error message in case
 * of polling failures.
 * @param errorChannelName the bean name for {@link MessageChannel} to use.
 * @return the spec.
 * @see MessagePublishingErrorHandler
 */
public PollerSpec errorChannel(String errorChannelName) {
    MessagePublishingErrorHandler errorHandler = new MessagePublishingErrorHandler();
    errorHandler.setDefaultErrorChannelName(errorChannelName);
    this.componentsToRegister.put(errorHandler, null);
    return errorHandler(errorHandler);
}
Also used : MessagePublishingErrorHandler(org.springframework.integration.channel.MessagePublishingErrorHandler)

Example 10 with MessagePublishingErrorHandler

use of org.springframework.integration.channel.MessagePublishingErrorHandler in project spring-integration by spring-projects.

the class DelayHandlerTests method errorChannelHeaderAndHandlerThrowsExceptionWithDelay.

@Test
public void errorChannelHeaderAndHandlerThrowsExceptionWithDelay() throws Exception {
    DirectChannel errorChannel = new DirectChannel();
    MessagePublishingErrorHandler errorHandler = new MessagePublishingErrorHandler();
    errorHandler.setDefaultErrorChannel(errorChannel);
    taskScheduler.setErrorHandler(errorHandler);
    this.setDelayExpression();
    this.startDelayerHandler();
    output.unsubscribe(resultHandler);
    errorChannel.subscribe(resultHandler);
    output.subscribe(message -> {
        throw new UnsupportedOperationException("intentional test failure");
    });
    Message<?> message = MessageBuilder.withPayload("test").setHeader("delay", "10").setErrorChannel(errorChannel).build();
    input.send(message);
    waitForLatch(10000);
    Message<?> errorMessage = resultHandler.lastMessage;
    assertEquals(MessageDeliveryException.class, errorMessage.getPayload().getClass());
    MessageDeliveryException exceptionPayload = (MessageDeliveryException) errorMessage.getPayload();
    assertSame(message.getPayload(), exceptionPayload.getFailedMessage().getPayload());
    assertEquals(UnsupportedOperationException.class, exceptionPayload.getCause().getClass());
    assertNotSame(Thread.currentThread(), resultHandler.lastThread);
}
Also used : MessagePublishingErrorHandler(org.springframework.integration.channel.MessagePublishingErrorHandler) DirectChannel(org.springframework.integration.channel.DirectChannel) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException) Test(org.junit.Test)

Aggregations

MessagePublishingErrorHandler (org.springframework.integration.channel.MessagePublishingErrorHandler)12 BeanFactoryChannelResolver (org.springframework.integration.support.channel.BeanFactoryChannelResolver)5 Test (org.junit.Test)4 ErrorHandlingTaskExecutor (org.springframework.integration.util.ErrorHandlingTaskExecutor)4 DirectChannel (org.springframework.integration.channel.DirectChannel)3 MessageDeliveryException (org.springframework.messaging.MessageDeliveryException)3 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)2 SimpleAsyncTaskExecutor (org.springframework.core.task.SimpleAsyncTaskExecutor)2 SourcePollingChannelAdapter (org.springframework.integration.endpoint.SourcePollingChannelAdapter)2 MessagingException (org.springframework.messaging.MessagingException)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 Log (org.apache.commons.logging.Log)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 BeanFactory (org.springframework.beans.factory.BeanFactory)1 BeanFactoryAware (org.springframework.beans.factory.BeanFactoryAware)1 BeanInitializationException (org.springframework.beans.factory.BeanInitializationException)1 TaskExecutor (org.springframework.core.task.TaskExecutor)1 ChannelTopic (org.springframework.data.redis.listener.ChannelTopic)1 MessageListenerAdapter (org.springframework.data.redis.listener.adapter.MessageListenerAdapter)1 Poller (org.springframework.integration.annotation.Poller)1