camel路由需要注意的点:外面必须加上<choice>标签,否则不能根据条件选择when还是otherwise
<choice>
<when>
</when>
<otherwise>
</otherwise>
</choice>
<routes xmlns="http://camel.apache.org/schema/spring">
<!-- 领取多个优惠券 -->
<route id="getCoupons">
<from uri="direct:getCoupons"/>
<!-- Save Origin Request Message: usage ${property.originRequest} -->
<setProperty propertyName="getCouponsRequest">
<simple>${in.body}</simple>
</setProperty>
<!--领取通用券-->
<to uri="bean:cardService?method=getCommonCoupons(${property.getCouponsRequest})"/>
<setProperty propertyName="getCouponsResponse">
<simple>${body}</simple>
</setProperty>
<choice>
<!-- 领取等级优惠券和生日券 -->
<when>
<simple>${body.data.lead.stageId} > 1</simple>
<!--领取等级券-->
<to uri="bean:cardService?method=getStageCoupons(${property.getCouponsRequest})"/>
<setProperty propertyName="getStageCoupons">
<simple>${body}</simple>
</setProperty>
<!--领取生日券-->
<to uri="bean:cardService?method=getBirthdayCoupons(${property.getCouponsRequest})"/>
<setProperty propertyName="getBirthdayCoupons">
<simple>${body}</simple>
</setProperty>
<!--把所有的券转换成一个请求对象-->
<bean ref="couponsTransform" method="toCouponsRequest(${property.getCouponsResponse},${property.getStageCoupons},${property.getBirthdayCoupons})"/>
<setProperty propertyName="toCouponsRequest">
<simple>${body}</simple>
</setProperty>
<choice >
<when>
<simple>${body.coupons.size} == 0</simple>
<!--无可领取的券,发送文本消息无可领取的券-->
<to uri="bean:messageService?method=sendNoCouponTextMessage(${property.toCouponsRequest})"/>
</when>
<otherwise>
<!--调用发送券类型的文本消息接口-->
<to uri="bean:messageService?method=sendCouponTextMessage(${property.toCouponsRequest})"/>
<!--调用领取多张券的消息接口-->
<to uri="bean:messageService?method=sendCoupons(${property.toCouponsRequest})"/>
</otherwise>
</choice>
</when>
<!-- 等级小于等于1 -->
<otherwise>
<choice>
<!--没有券可以领,发送图片-->
<when>
<simple>${body.data.coupons} == null || ${body.data.coupons.size} == 0 </simple>
<!--调用发送图片消息接口-->
<to uri="bean:messageService?method=sendImageMessage(${property.getCouponsResponse.data})"/>
</when>
<!--有券可以领,发送等级1文本+发券信息-->
<otherwise>
<!--调用发送券类型的文本消息接口-->
<to uri="bean:messageService?method=sendCouponTextMessage(${property.getCouponsResponse.data})"/>
<!--调用领取多张券的消息接口-->
<to uri="bean:messageService?method=sendCoupons(${property.getCouponsResponse.data})"/>
</otherwise>
</choice>
</otherwise>
</choice>
</route>