Spring integration 如何使用spring integration dsl解组xml

Spring integration 如何使用spring integration dsl解组xml,spring-integration,spring-integration-dsl,Spring Integration,Spring Integration Dsl,我正在研究spring集成dsl。需求是从队列中读取xml消息,根据消息头值,我需要调用不同的服务。我能够从队列中获取消息,但无法在dsl中编写代码,以便将xml消息解组到对象。有人能帮忙吗?我有解组器,但无法与dsl连接 IntegrationFlows .from(Jms.inboundGateway(connectionFactory) .destination(someQueue)

我正在研究spring集成dsl。需求是从队列中读取xml消息,根据消息头值,我需要调用不同的服务。我能够从队列中获取消息,但无法在dsl中编写代码,以便将xml消息解组到对象。有人能帮忙吗?我有解组器,但无法与dsl连接

 IntegrationFlows
            .from(Jms.inboundGateway(connectionFactory)
                    .destination(someQueue)
                    .configureListenerContainer(spec -> spec.get().setSessionTransacted(true)))
            .transform(??)

首先,您可以使用编组消息转换器配置
Jms.inboundGateway()

/**
 * @param messageConverter the messageConverter.
 * @return the spec.
 * @see ChannelPublishingJmsMessageListener#setMessageConverter(MessageConverter)
 */
public S jmsMessageConverter(MessageConverter messageConverter) {
    this.target.getListener().setMessageConverter(messageConverter);
    return _this();
}
/**
 * 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> {
但如果您仍然坚持<代码>转换()/<代码>,则考虑使用<代码> unMARSCALIN变压器:

/**
 * @param messageConverter the messageConverter.
 * @return the spec.
 * @see ChannelPublishingJmsMessageListener#setMessageConverter(MessageConverter)
 */
public S jmsMessageConverter(MessageConverter messageConverter) {
    this.target.getListener().setMessageConverter(messageConverter);
    return _this();
}
/**
 * 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> {
/**
*委托给OXM的{@link Transformer}的实现
*{@link Unmarshaller}。期望负载的类型为{@link Document},
*{@link String}、{@link File}、{@link Source}或具有
*{@link SourceFactory},可以转换为{@link Source}。如果
*{@link#alwaysUseSourceFactory}设置为true,则{@link SourceFactory}
*将用于创建{@link Source},而不考虑负载类型。
*
*如果有效负载为空,则忽略{@link#alwaysUseSourceFactory}
*{@link org.springframework.ws.mime.MimeMessage}。
*
*解组器可以返回消息,但如果返回值不是
*已存在消息实例,将使用该实例创建新消息
*返回值作为其有效负载。
*
*@作者Jonas Partner
*@作者Artem Bilan
*/
公共类解组器Transformer扩展了AbstractPayloadTransformer{

谢谢。我做了以下更改以使其正常工作。这是从(Jms.inboundGateway(connectionFactory)、destination(sourceQueue)、jmsMessageConverter(new MarshallingMessageConverter(jaxbMarshaller()).configureListenerContainer(spec->spec.get)开始的正确方法吗().setSessionTransact(true))@Bean public org.springframework.oxm.Marshaller jaxbMarshaller(){Jaxb2Marshaller Jaxb2Marshaller=new Jaxb2Marshaller();…返回Jaxb2Marshaller;}