问题
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(??)
回答1:
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
来源:https://stackoverflow.com/questions/49734473/how-to-unmarshall-xml-using-spring-integration-dsl