spring-integration icon indicating copy to clipboard operation
spring-integration copied to clipboard

Add header-mapper to int-jms:channel [INT-2816]

Open spring-operator opened this issue 13 years ago • 0 comments

William Gorder opened INT-2816 and commented

We are using a header mapper to get the amount of retries off of an ActiveMqMessage.

/**
* A custom JMS header mapper extending the functionality provided by {@link DefaultJmsHeaderMapper}
* to add a header defining the re-delivery count
* 
 */
@Component("activeMQRedeliveryCounterMapper")
public class ActiveMQRedeliveryCounterMapper extends DefaultJmsHeaderMapper
{
    /**
     * For ActiveMQ, the redeliveryCounter is not a message property, it is accessed by the
     * proprietary getRedeliveryCounter() method. This means a custom header mapper is required to
     * gain access to it as an SI header.
     */
    @Override
    public Map<String, Object> toHeaders(Message jmsMessage)
    {
        Map<String, Object> headers = super.toHeaders(jmsMessage);
        if (jmsMessage instanceof ActiveMQMessage)
        {
            ActiveMQMessage amqMessage = (ActiveMQMessage) jmsMessage;
            int redeliveryCounter = amqMessage.getRedeliveryCounter();
            headers.put("amq_redeliveryCounter", redeliveryCounter);
        }
        return headers;
    }
}

Our goal was to get away from using a combination of int-jms:output-channel-adapter and the int-jms:message-driven-channel-adapter and just use jms backed channels. However it does not seem that it is possible to define a header mapper on this component. Is there a workaround for this or a reason it is not available?


Affects: 2.1.4

2 votes, 4 watchers

spring-operator avatar Nov 13 '12 08:11 spring-operator