3

I working on spring integration dsl. The requirement is read a xml message from queue, based on message header value, i need to invoke a different service. I was able to fetch the message from queue but unable write code in dsl for unmarshalling the xml message to object. Can someone help & i have my unmarshaller but unable to wire it with dsl

 IntegrationFlows
            .from(Jms.inboundGateway(connectionFactory)
                    .destination(someQueue)
                    .configureListenerContainer(spec -> spec.get().setSessionTransacted(true)))
            .transform(??)
nagendra
  • 593
  • 1
  • 9
  • 29

1 Answers1

4

First of all you can configure Jms.inboundGateway() with the MarshallingMessageConverter:

/**
 * @param messageConverter the messageConverter.
 * @return the spec.
 * @see ChannelPublishingJmsMessageListener#setMessageConverter(MessageConverter)
 */
public S jmsMessageConverter(MessageConverter messageConverter) {
    this.target.getListener().setMessageConverter(messageConverter);
    return _this();
}

But if you still insist for the .transform(), then consider to use UnmarshallingTransformer:

/**
 * An implementation of {@link Transformer} that delegates to an OXM
 * {@link Unmarshaller}. Expects the payload to be of type {@link Document},
 * {@link String}, {@link File}, {@link Source} or to have an instance of
 * {@link SourceFactory} that can convert to a {@link Source}. If
 * {@link #alwaysUseSourceFactory} is set to true, then the {@link SourceFactory}
 * will be used to create the {@link Source} regardless of payload type.
 * <p>
 * The {@link #alwaysUseSourceFactory} is ignored if payload is
 * {@link org.springframework.ws.mime.MimeMessage}.
 * <p>
 * The Unmarshaller may return a Message, but if the return value is not
 * already a Message instance, a new Message will be created with that
 * return value as its payload.
 *
 * @author Jonas Partner
 * @author Artem Bilan
 */
public class UnmarshallingTransformer extends AbstractPayloadTransformer<Object, Object> {

https://docs.spring.io/spring-integration/docs/5.0.4.RELEASE/reference/html/xml.html#xml-unmarshalling-transformer

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • 1
    Thanks. I made the following changes to make it work. Is this the right way `.from(Jms.inboundGateway(connectionFactory) .destination(sourceQueue) .jmsMessageConverter(new MarshallingMessageConverter(jaxbMarshaller())) .configureListenerContainer(spec -> spec.get().setSessionTransacted(true))) @Bean public org.springframework.oxm.Marshaller jaxbMarshaller() { Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller(); .... return jaxb2Marshaller; }` – nagendra Apr 10 '18 at 08:48