Spring集成 - 将完整的消息保存到数据库并再次读取

时间:2016-12-08 16:24:12

标签: json serialization spring-integration spring-amqp

是否有可能将完整邮件序列化为某种格式,例如JSON并将其保存到db。在此之后,我将使用完整标头反序列化消息并将其发送到amqp。类似的东西:

<int:object-to-json-transformer object-mapper="mapper" />
<int-jdbc:outbound-channel-adapter channel="srk2" data-source="dataSource" query="insert into messages (serialized_message) values (:message_with_headers)" />

然后

<int-jdbc:inbound-channel-adapter query="SELECT auto_inc_id,serialized_message FROM messages" channel="oc" data-source="dataSource">
<int-amqp:outbound-channel-adapter exchange-name="bookmakers" amqp-template="rabbitTemplate" channel="oc" order="1" />
<int-jdbc:outbound-channel-adapter channel="oc" data-source="dataSource" query="DELETE FROM messages WHERE auto_incr_id IN (:auto_inc_id)" order="2" />

1 个答案:

答案 0 :(得分:1)

行。看看你可以使用<int:object-to-json-transformer>或任何其他类似的变压器完全做到这一点。但你必须在它面前放置这个技巧:

<service-activator expression="T(org.springframework.integration.support.MessageBuilder).withPayload(#root)"/>

仅仅因为第一个仅针对payload进行转换。因此,要存储标题,您必须将完整的信息发送到payload

此问题还有其他组件 - <claim-check>,它确实将整个邮件存储在数据库中:http://docs.spring.io/spring-integration/docs/4.3.5.RELEASE/reference/html/messaging-transformation-chapter.html#claim-check