org.springframework.integration.StaticMessageHeaderAccessor Java Examples
The following examples show how to use
org.springframework.integration.StaticMessageHeaderAccessor.
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: RocketMQMessageChannelBinder.java From spring-cloud-alibaba with Apache License 2.0 | 6 votes |
@Override protected MessageHandler getPolledConsumerErrorMessageHandler( ConsumerDestination destination, String group, ExtendedConsumerProperties<RocketMQConsumerProperties> properties) { return message -> { if (message.getPayload() instanceof MessagingException) { AcknowledgmentCallback ack = StaticMessageHeaderAccessor .getAcknowledgmentCallback( ((MessagingException) message.getPayload()) .getFailedMessage()); if (ack != null) { if (properties.getExtension().shouldRequeue()) { ack.acknowledge(Status.REQUEUE); } else { ack.acknowledge(Status.REJECT); } } } }; }
Example #2
Source File: KafkaMessageChannelBinder.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 5 votes |
@Override protected MessageHandler getPolledConsumerErrorMessageHandler( ConsumerDestination destination, String group, ExtendedConsumerProperties<KafkaConsumerProperties> properties) { if (properties.getExtension().isEnableDlq()) { return getErrorMessageHandler(destination, group, properties); } final MessageHandler superHandler = super.getErrorMessageHandler(destination, group, properties); return (message) -> { ConsumerRecord<?, ?> record = (ConsumerRecord<?, ?>) message.getHeaders() .get(KafkaHeaders.RAW_DATA); if (!(message instanceof ErrorMessage)) { logger.error("Expected an ErrorMessage, not a " + message.getClass().toString() + " for: " + message); } else if (record == null) { if (superHandler != null) { superHandler.handleMessage(message); } } else { if (message.getPayload() instanceof MessagingException) { AcknowledgmentCallback ack = StaticMessageHeaderAccessor .getAcknowledgmentCallback( ((MessagingException) message.getPayload()) .getFailedMessage()); if (ack != null) { if (isAutoCommitOnError(properties)) { ack.acknowledge(AcknowledgmentCallback.Status.REJECT); } else { ack.acknowledge(AcknowledgmentCallback.Status.REQUEUE); } } } } }; }
Example #3
Source File: RabbitMessageChannelBinder.java From spring-cloud-stream-binder-rabbit with Apache License 2.0 | 5 votes |
@Override protected MessageHandler getPolledConsumerErrorMessageHandler( ConsumerDestination destination, String group, ExtendedConsumerProperties<RabbitConsumerProperties> properties) { MessageHandler handler = getErrorMessageHandler(destination, group, properties); if (handler != null) { return handler; } final MessageHandler superHandler = super.getErrorMessageHandler(destination, group, properties); return message -> { Message amqpMessage = (Message) message.getHeaders() .get(AmqpMessageHeaderErrorMessageStrategy.AMQP_RAW_MESSAGE); if (!(message instanceof ErrorMessage)) { logger.error("Expected an ErrorMessage, not a " + message.getClass().toString() + " for: " + message); } else if (amqpMessage == null) { if (superHandler != null) { superHandler.handleMessage(message); } } else { if (message.getPayload() instanceof MessagingException) { AcknowledgmentCallback ack = StaticMessageHeaderAccessor .getAcknowledgmentCallback( ((MessagingException) message.getPayload()) .getFailedMessage()); if (ack != null) { if (properties.getExtension().isRequeueRejected()) { ack.acknowledge(Status.REQUEUE); } else { ack.acknowledge(Status.REJECT); } } } } }; }