编写自己的 Spring PayloadTransformer 并加载它
write own Spring PayloadTransformer and load it
我目前正在使用 citrus-framework 来测试应用程序。
我的一个接口使用 Protobuf,我想实现一个 protobuf-to-json-transformer,它与 spring-integration 兼容,可以像下面一样使用它,但使用我的转换器而不是对象- 到字符串转换器:
<int:channel id="configRawReplies" />
<int:object-to-string-transformer id="configtransformer" input-channel="configRawReplies" output-channel="configResponse" />
<int:channel id="configResponse">
<int:queue />
</int:channel>
现在我有一个完全像 object-to-string-transformer 的原型,我正在加载它:
<bean id="Proto2Json" class="com.nobody.citrus.transformer.ProtoToJSONString">
<property name="input-channel" value="none"/>
<property name="output-channel" value="none"/>
</bean>
但是失败了。
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'Proto2Json' defined in URL [file:/Users/nobody/DevOops/test/citrus-scala/target/test-classes/citrus-context.xml]:
Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException:
Invalid property 'input-channel' of bean class [com.pme.citrus.transformer.ProtoToJSONString]:
Bean property 'input-channel' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
有人知道或提示可以在网上查看什么吗?
BR
没错。您确实需要遵循 ObjectToStringTransformer
中的设计来实现您自己的 AbstractPayloadTransformer
。在您的应用程序上下文中,该定义必须是一个普通的 <bean>
定义。
唯一的问题是您不明白为什么我们真的有所有这些自定义标签来利用 input-channel
和 output-channel
属性。重点是这个
<int:object-to-string-transformer>
,例如,为应用程序上下文提供了几个 bean,包括提到的 ObjectToStringTransformer
实例,一个 MessageTransformingHandler
,最后,ConsumerEndpointFactoryBean
连接一个MessageHandler
与 inputChannel
.
因此,您在这里缺少的是自定义 AbstractPayloadTransformer
实现的通用 <int:transformer>
定义:
<bean id="Proto2Json" class="com.nobody.citrus.transformer.ProtoToJSONString"/>
<int:tranformer ref="Proto2Json" input-channel="configRawReplies" output-channel="configResponse"/>
请阅读更多参考手册以避免将来出现类似的讨论:
https://docs.spring.io/spring-integration/reference/html/overview.html#programming-tips
https://docs.spring.io/spring-integration/reference/html/messaging-transformation-chapter.html
我目前正在使用 citrus-framework 来测试应用程序。 我的一个接口使用 Protobuf,我想实现一个 protobuf-to-json-transformer,它与 spring-integration 兼容,可以像下面一样使用它,但使用我的转换器而不是对象- 到字符串转换器:
<int:channel id="configRawReplies" />
<int:object-to-string-transformer id="configtransformer" input-channel="configRawReplies" output-channel="configResponse" />
<int:channel id="configResponse">
<int:queue />
</int:channel>
现在我有一个完全像 object-to-string-transformer 的原型,我正在加载它:
<bean id="Proto2Json" class="com.nobody.citrus.transformer.ProtoToJSONString">
<property name="input-channel" value="none"/>
<property name="output-channel" value="none"/>
</bean>
但是失败了。
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'Proto2Json' defined in URL [file:/Users/nobody/DevOops/test/citrus-scala/target/test-classes/citrus-context.xml]:
Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException:
Invalid property 'input-channel' of bean class [com.pme.citrus.transformer.ProtoToJSONString]:
Bean property 'input-channel' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
有人知道或提示可以在网上查看什么吗?
BR
没错。您确实需要遵循 ObjectToStringTransformer
中的设计来实现您自己的 AbstractPayloadTransformer
。在您的应用程序上下文中,该定义必须是一个普通的 <bean>
定义。
唯一的问题是您不明白为什么我们真的有所有这些自定义标签来利用 input-channel
和 output-channel
属性。重点是这个
<int:object-to-string-transformer>
,例如,为应用程序上下文提供了几个 bean,包括提到的 ObjectToStringTransformer
实例,一个 MessageTransformingHandler
,最后,ConsumerEndpointFactoryBean
连接一个MessageHandler
与 inputChannel
.
因此,您在这里缺少的是自定义 AbstractPayloadTransformer
实现的通用 <int:transformer>
定义:
<bean id="Proto2Json" class="com.nobody.citrus.transformer.ProtoToJSONString"/>
<int:tranformer ref="Proto2Json" input-channel="configRawReplies" output-channel="configResponse"/>
请阅读更多参考手册以避免将来出现类似的讨论:
https://docs.spring.io/spring-integration/reference/html/overview.html#programming-tips
https://docs.spring.io/spring-integration/reference/html/messaging-transformation-chapter.html