org.springframework.integration.support.DefaultErrorMessageStrategy Java Examples
The following examples show how to use
org.springframework.integration.support.DefaultErrorMessageStrategy.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestChannelBinder.java From spring-cloud-stream with Apache License 2.0 | 5 votes |
@Override protected MessageProducer createConsumerEndpoint(ConsumerDestination destination, String group, ConsumerProperties properties) throws Exception { ErrorMessageStrategy errorMessageStrategy = new DefaultErrorMessageStrategy(); SubscribableChannel siBinderInputChannel = ((SpringIntegrationConsumerDestination) destination) .getChannel(); IntegrationMessageListeningContainer messageListenerContainer = new IntegrationMessageListeningContainer(); IntegrationBinderInboundChannelAdapter adapter = new IntegrationBinderInboundChannelAdapter( messageListenerContainer); String groupName = StringUtils.hasText(group) ? group : "anonymous"; ErrorInfrastructure errorInfrastructure = registerErrorInfrastructure(destination, groupName, properties); if (properties.getMaxAttempts() > 1) { adapter.setRetryTemplate(buildRetryTemplate(properties)); adapter.setRecoveryCallback(errorInfrastructure.getRecoverer()); } else { adapter.setErrorMessageStrategy(errorMessageStrategy); adapter.setErrorChannel(errorInfrastructure.getErrorChannel()); } siBinderInputChannel.subscribe(messageListenerContainer); return adapter; }
Example #2
Source File: RabbitMessageChannelBinder.java From spring-cloud-stream-binder-rabbit with Apache License 2.0 | 4 votes |
@Override protected MessageHandler createProducerMessageHandler( final ProducerDestination producerDestination, ExtendedProducerProperties<RabbitProducerProperties> producerProperties, MessageChannel errorChannel) { Assert.state( !HeaderMode.embeddedHeaders.equals(producerProperties.getHeaderMode()), "the RabbitMQ binder does not support embedded headers since RabbitMQ supports headers natively"); String prefix = producerProperties.getExtension().getPrefix(); String exchangeName = producerDestination.getName(); String destination = StringUtils.isEmpty(prefix) ? exchangeName : exchangeName.substring(prefix.length()); final AmqpOutboundEndpoint endpoint = new AmqpOutboundEndpoint( buildRabbitTemplate(producerProperties.getExtension(), errorChannel != null)); endpoint.setExchangeName(producerDestination.getName()); RabbitProducerProperties extendedProperties = producerProperties.getExtension(); boolean expressionInterceptorNeeded = expressionInterceptorNeeded( extendedProperties); Expression routingKeyExpression = extendedProperties.getRoutingKeyExpression(); if (!producerProperties.isPartitioned()) { if (routingKeyExpression == null) { endpoint.setRoutingKey(destination); } else { if (expressionInterceptorNeeded) { endpoint.setRoutingKeyExpressionString("headers['" + RabbitExpressionEvaluatingInterceptor.ROUTING_KEY_HEADER + "']"); } else { endpoint.setRoutingKeyExpression(routingKeyExpression); } } } else { if (routingKeyExpression == null) { endpoint.setRoutingKeyExpression( buildPartitionRoutingExpression(destination, false)); } else { if (expressionInterceptorNeeded) { endpoint.setRoutingKeyExpression( buildPartitionRoutingExpression("headers['" + RabbitExpressionEvaluatingInterceptor.ROUTING_KEY_HEADER + "']", true)); } else { endpoint.setRoutingKeyExpression(buildPartitionRoutingExpression( routingKeyExpression.getExpressionString(), true)); } } } if (extendedProperties.getDelayExpression() != null) { if (expressionInterceptorNeeded) { endpoint.setDelayExpressionString("headers['" + RabbitExpressionEvaluatingInterceptor.DELAY_HEADER + "']"); } else { endpoint.setDelayExpression(extendedProperties.getDelayExpression()); } } DefaultAmqpHeaderMapper mapper = DefaultAmqpHeaderMapper.outboundMapper(); List<String> headerPatterns = new ArrayList<>(extendedProperties.getHeaderPatterns().length + 3); headerPatterns.add("!" + BinderHeaders.PARTITION_HEADER); headerPatterns.add("!" + IntegrationMessageHeaderAccessor.SOURCE_DATA); headerPatterns.add("!" + IntegrationMessageHeaderAccessor.DELIVERY_ATTEMPT); headerPatterns.addAll(Arrays.asList(extendedProperties.getHeaderPatterns())); mapper.setRequestHeaderNames( headerPatterns.toArray(new String[headerPatterns.size()])); endpoint.setHeaderMapper(mapper); endpoint.setDefaultDeliveryMode(extendedProperties.getDeliveryMode()); endpoint.setBeanFactory(this.getBeanFactory()); if (errorChannel != null) { checkConnectionFactoryIsErrorCapable(); endpoint.setReturnChannel(errorChannel); endpoint.setConfirmNackChannel(errorChannel); String ackChannelBeanName = StringUtils .hasText(extendedProperties.getConfirmAckChannel()) ? extendedProperties.getConfirmAckChannel() : IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME; if (!ackChannelBeanName.equals(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME) && !getApplicationContext().containsBean(ackChannelBeanName)) { GenericApplicationContext context = (GenericApplicationContext) getApplicationContext(); context.registerBean(ackChannelBeanName, DirectChannel.class, () -> new DirectChannel()); } endpoint.setConfirmAckChannelName(ackChannelBeanName); endpoint.setConfirmCorrelationExpressionString("#root"); endpoint.setErrorMessageStrategy(new DefaultErrorMessageStrategy()); } endpoint.setHeadersMappedLast(true); return endpoint; }