Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring integration Spring集成-JMS输出适配器-使用消息转换器以字符串形式发送对象_Spring Integration - Fatal编程技术网

Spring integration Spring集成-JMS输出适配器-使用消息转换器以字符串形式发送对象

Spring integration Spring集成-JMS输出适配器-使用消息转换器以字符串形式发送对象,spring-integration,Spring Integration,问题:JMS出站通道适配器上的消息转换器正在以字节而不是JMS文本消息的形式发送对象I解组。是否可以将消息转换器设置为显式地告诉它以JMS文本消息而不是字节的形式发送?我想在拆分器和出站器之间放置一个转换器,它只返回一个字符串,但效率似乎很低 参考文档: 代码: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" x

问题:JMS出站通道适配器上的消息转换器正在以字节而不是JMS文本消息的形式发送对象I解组。是否可以将消息转换器设置为显式地告诉它以JMS文本消息而不是字节的形式发送?我想在拆分器和出站器之间放置一个转换器,它只返回一个字符串,但效率似乎很低

参考文档:

代码:

<?xml version="1.0" encoding="UTF-8"?>
<beans 
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:int="http://www.springframework.org/schema/integration"
    xmlns:jms="http://www.springframework.org/schema/integration/jms"
    xmlns:stream="http://www.springframework.org/schema/integration/stream"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:oxm="http://www.springframework.org/schema/oxm"
    xsi:schemaLocation="
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/integration
            http://www.springframework.org/schema/integration/spring-integration.xsd
            http://www.springframework.org/schema/integration/jms
            http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd
            http://www.springframework.org/schema/integration/stream
            http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/jee
            http://www.springframework.org/schema/jee/spring-jee.xsd
            http://www.springframework.org/schema/oxm
            http://www.springframework.org/schema/oxm/spring-oxm.xsd">


        <int:chain id="fooChain" input-channel="requestChannel">    

            <!-- Performs processing action - Returns List<Foo> objects -->
            <int:service-activator ref="fooListener" method="processFoo"/>

            <int:splitter />

            <!-- Covert messages and send to mq queue -->       
            <jms:outbound-channel-adapter 
                id="fooRequestsChannel"
                destination="externalAppRequestQueue"
                message-converter="fooMessageConverter">
            </jms:outbound-channel-adapter>

        </int:chain> 


        <bean id="oxmFooMessageConverter" class="org.springframework.jms.support.converter.MarshallingMessageConverter">
              <property name="marshaller" ref="fooMarshaller" />
              <property name="unmarshaller" ref="fooMarshaller" />
               <!-- SOLUTION ADDED HERE: START --> 
              <property name="targetType" value="TEXT"/>
               <!-- SOLUTION ADDED HERE: END-->
        </bean>


         <oxm:jaxb2-marshaller id="fooMarshaller">  
            <oxm:class-to-be-bound name="com.test.foo" />
         </oxm:jaxb2-marshaller>

    </beans>

解决方案:

<?xml version="1.0" encoding="UTF-8"?>
<beans 
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:int="http://www.springframework.org/schema/integration"
    xmlns:jms="http://www.springframework.org/schema/integration/jms"
    xmlns:stream="http://www.springframework.org/schema/integration/stream"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:oxm="http://www.springframework.org/schema/oxm"
    xsi:schemaLocation="
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/integration
            http://www.springframework.org/schema/integration/spring-integration.xsd
            http://www.springframework.org/schema/integration/jms
            http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd
            http://www.springframework.org/schema/integration/stream
            http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/jee
            http://www.springframework.org/schema/jee/spring-jee.xsd
            http://www.springframework.org/schema/oxm
            http://www.springframework.org/schema/oxm/spring-oxm.xsd">


        <int:chain id="fooChain" input-channel="requestChannel">    

            <!-- Performs processing action - Returns List<Foo> objects -->
            <int:service-activator ref="fooListener" method="processFoo"/>

            <int:splitter />

            <!-- Covert messages and send to mq queue -->       
            <jms:outbound-channel-adapter 
                id="fooRequestsChannel"
                destination="externalAppRequestQueue"
                message-converter="fooMessageConverter">
            </jms:outbound-channel-adapter>

        </int:chain> 


        <bean id="oxmFooMessageConverter" class="org.springframework.jms.support.converter.MarshallingMessageConverter">
              <property name="marshaller" ref="fooMarshaller" />
              <property name="unmarshaller" ref="fooMarshaller" />
               <!-- SOLUTION ADDED HERE: START --> 
              <property name="targetType" value="TEXT"/>
               <!-- SOLUTION ADDED HERE: END-->
        </bean>


         <oxm:jaxb2-marshaller id="fooMarshaller">  
            <oxm:class-to-be-bound name="com.test.foo" />
         </oxm:jaxb2-marshaller>

    </beans>
将以下属性添加到上面的oxmFooMessageConverter。JMS消息将作为文本字符串发送到队列,而不是字节。以上示例已更新

<property name="targetType" value="TEXT"/>

M-M-M。问题是什么?您已经这样做了:
messageconverter=“fooMessageConverter”

你有什么问题

如果需要
String
,则
MarshallingMessageConverter
具有一个选项:

/**
 * Specify whether {@link #toMessage(Object, Session)} should marshal to
 * a {@link BytesMessage} or a {@link TextMessage}.
 * <p>The default is {@link MessageType#BYTES}, i.e. this converter marshals
 * to a {@link BytesMessage}. Note that the default version of this converter
 * supports {@link MessageType#BYTES} and {@link MessageType#TEXT} only.
 * @see MessageType#BYTES
 * @see MessageType#TEXT
 */
public void setTargetType(MessageType targetType) {
    Assert.notNull(targetType, "MessageType must not be null");
    this.targetType = targetType;
}
/**
*指定{@link#toMessage(Object,Session)}是否应封送到
*{@link BytesMessage}或{@link TextMessage}。
*默认值为{@link MessageType#BYTES},即此转换器进行封送处理
*到{@link BytesMessage}。请注意,此转换器的默认版本
*仅支持{@link MessageType#BYTES}和{@link MessageType#TEXT}。
*@参见MessageType#字节
*@see MessageType#TEXT
*/
public void setTargetType(MessageType targetType){
Assert.notNull(targetType,“MessageType不能为null”);
this.targetType=targetType;
}

M-M-M。问题是什么?您已经这样做了:
messageconverter=“fooMessageConverter”

你有什么问题

如果需要
String
,则
MarshallingMessageConverter
具有一个选项:

/**
 * Specify whether {@link #toMessage(Object, Session)} should marshal to
 * a {@link BytesMessage} or a {@link TextMessage}.
 * <p>The default is {@link MessageType#BYTES}, i.e. this converter marshals
 * to a {@link BytesMessage}. Note that the default version of this converter
 * supports {@link MessageType#BYTES} and {@link MessageType#TEXT} only.
 * @see MessageType#BYTES
 * @see MessageType#TEXT
 */
public void setTargetType(MessageType targetType) {
    Assert.notNull(targetType, "MessageType must not be null");
    this.targetType = targetType;
}
/**
*指定{@link#toMessage(Object,Session)}是否应封送到
*{@link BytesMessage}或{@link TextMessage}。
*默认值为{@link MessageType#BYTES},即此转换器进行封送处理
*到{@link BytesMessage}。请注意,此转换器的默认版本
*仅支持{@link MessageType#BYTES}和{@link MessageType#TEXT}。
*@参见MessageType#字节
*@see MessageType#TEXT
*/
public void setTargetType(MessageType targetType){
Assert.notNull(targetType,“MessageType不能为null”);
this.targetType=targetType;
}

我遇到的问题是,在上面的当前示例中。它正在以字节格式而不是字符串格式将我的对象发送到队列?接收应用程序抛出错误,表示它不是JMS文本消息格式,而是字节。阅读spring文档时,听起来好像我必须将我的字符串对象发送到输出适配器,以JMS文本消息的形式发送。OK。
MarshallingMessageConverter.setTargetType(MessageType.TEXT)
对您有帮助吗?你为什么不注意我的解释?是的,这很有效。为文本值的目标类型指定属性类型。我遇到的问题是在上面的当前示例中。它正在以字节格式而不是字符串格式将我的对象发送到队列?接收应用程序抛出错误,表示它不是JMS文本消息格式,而是字节。阅读spring文档时,听起来好像我必须将我的字符串对象发送到输出适配器,以JMS文本消息的形式发送。OK。
MarshallingMessageConverter.setTargetType(MessageType.TEXT)
对您有帮助吗?你为什么不注意我的解释?是的,这很有效。为文本值的目标类型指定属性类型。