我正在研究spring integration dsl。要求是从队列中读取xml消息,根据消息头值,我需要调用不同的服务。我能够从队列中获取消息,但无法在dsl中编写代码以将xml消息解组为object。有人可以帮忙吗?我有我的unmarshaller但无法用dsl
连线 IntegrationFlows
.from(Jms.inboundGateway(connectionFactory)
.destination(someQueue)
.configureListenerContainer(spec -> spec.get().setSessionTransacted(true)))
.transform(??)
答案 0 :(得分:3)
首先,您可以使用Jms.inboundGateway()
配置MarshallingMessageConverter
:
/**
* @param messageConverter the messageConverter.
* @return the spec.
* @see ChannelPublishingJmsMessageListener#setMessageConverter(MessageConverter)
*/
public S jmsMessageConverter(MessageConverter messageConverter) {
this.target.getListener().setMessageConverter(messageConverter);
return _this();
}
但如果您仍坚持使用.transform()
,请考虑使用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> {