在中,我有如下消息:
{
"name":"House",
"attributeIds": [1,3,5]
}我需要使用Rest服务丰富/转换此消息,这将给出属性值。
例如,http://restservice.com/attributes?id=1,3,5将用
{"attributes": [
{"id": 1, "value":"Waterproof"},
{"id": 3, "value":"SoundProof"},
{"id": 5, "value":"Concrete"}
]}最后一个对象应该如下所示:
{
"name":"House",
"attributes": [
{"id": 1, "value":"Waterproof"},
{"id": 3, "value":"SoundProof"},
{"id": 5, "value":"Concrete"}
]
}如何才能做到这一点?
应该是这样吗?continue=273&v=DHPsWDgEUXg
InboundAdapter -> Enricher ->请求通道->服务激活器-> Enricher ->出站适配器?
发布于 2019-10-02 17:41:20
这确实是内容丰富的一个典型任务。
因此,您需要的是将传入的JSON反序列化为一个普通的Map。使用request-payload-expression="payload.attributeIds"将ids列表作为子流请求的有效负载。
request-channel上的订阅者可以是简单的Spring HTTP出站网关,以调用REST服务并返回一条attributes消息。这个网关不需要output-channel就可以通过replyChannel报头将其结果返回到content-enricher中。
当此回复消息涉及到content-enricher时,可以使用一个简单的<int:property name="attributes">在请求Map中填充该新选项。
之后,您可以从该映射中移除attributeIds键,并在需要时将其序列化回JSON。
更新
下面是一个示例,说明如何使用Java和Spring:https://github.com/artembilan/sandbox/tree/master/spring-integration-enricher实现
https://stackoverflow.com/questions/58205432
复制相似问题