Apache camel 驼峰将Json解组为bean上的参数';s法
我在调用时将消息体解组为pojo时遇到了一个非常糟糕的问题 我定义了一条非常简单的路线,将身体解组到我的自定义pojo中:Apache camel 驼峰将Json解组为bean上的参数';s法,apache-camel,unmarshalling,parameterbinding,Apache Camel,Unmarshalling,Parameterbinding,我在调用时将消息体解组为pojo时遇到了一个非常糟糕的问题 我定义了一条非常简单的路线,将身体解组到我的自定义pojo中: <dataFormats> <json id="json" library="Jackson" unmarshalTypeName="com.trumin.domain.model.result.Result" /> </dataFormats> <camel:route>
<dataFormats>
<json id="json" library="Jackson" unmarshalTypeName="com.trumin.domain.model.result.Result" />
</dataFormats>
<camel:route>
<camel:from
uri="activemq:topic:result?clientId=sswric_01&durableSubscriptionName=sendSMSWhenResultIsCalculated" />
<marshal ref="json" />
<bean beanType="com.trumin.communications.sms.TimeResultSMSSender"
method="sendTextToUserAfterTimeResultBeingSaved(${body})" />
</camel:route>
</camelContext>
接收json数据格式中定义的Result类型的参数,并且在传递消息时不会调用该参数
如果修改方法签名以接受字符串而不是结果:
sendTextToUserAfterTimeResultBeingSaved(String s);
然后调用它,字符串包含结果json表示
我想要达到的目标有什么方法可以实现吗
我还尝试过从路由中删除(${body})规范,尝试过其他解组库,尝试过阅读所有camel教程和参数绑定的链接,阅读了大部分camel-in-action章节,但仍然找不到我的答案 最后。。。这修正了它:
<camelContext xmlns="http://camel.apache.org/schema/spring">
<camel:dataFormats>
<camel:json id="jsonToResult" library="Jackson" unmarshalTypeName="com.trumin.domain.model.result.Result" />
</camel:dataFormats>
<camel:route>
<camel:from
uri="activemq:topic:result?clientId=sswric_01&durableSubscriptionName=sendSMSWhenResultIsCalculated" />
<camel:unmarshal ref="jsonToResult" />
<camel:bean beanType="com.trumin.communications.sms.TimeResultSMSSender"
method="sendTextToUserAfterTimeResultBeingSaved" />
</camel:route>
</camelContext>
最后。。。这修正了它:
<camelContext xmlns="http://camel.apache.org/schema/spring">
<camel:dataFormats>
<camel:json id="jsonToResult" library="Jackson" unmarshalTypeName="com.trumin.domain.model.result.Result" />
</camel:dataFormats>
<camel:route>
<camel:from
uri="activemq:topic:result?clientId=sswric_01&durableSubscriptionName=sendSMSWhenResultIsCalculated" />
<camel:unmarshal ref="jsonToResult" />
<camel:bean beanType="com.trumin.communications.sms.TimeResultSMSSender"
method="sendTextToUserAfterTimeResultBeingSaved" />
</camel:route>
</camelContext>
我认为您需要更改路线中解组的封送。(除非在键入问题时输入错误!)据我所知,您正在向activemq主题发送一个JSON字符串,并且希望结果对象到达该方法?我认为您需要在路由中更改marshal for unmarshal。(除非键入问题时输入错误!)据我所知,您正在向activemq主题发送一个JSON字符串,并且希望结果对象到达该方法?