首页 > 解决方案 > How to get UpsertResult when using Mongo Outbound channel adapter?

问题描述

I'm using spring integration to store data in a mongo database. I'm using the java classes (MongoDbStoringMessageHandler), not the xml configuration and I can't find the way to get the results when adding some data in the database...

Is it possible ? How ?

标签: javaspringmongodbspring-integration

解决方案


MongoDbStoringMessageHandler是一个单向组件,它不返回任何东西。

考虑使用 aMongoDbOutboundGateway而不是CollectionCallback注入的地方,您可以在其中执行 anupdateMany()UpdateResult从该网关获取回复。

在参考手册中查看更多信息:https ://docs.spring.io/spring-integration/reference/html/mongodb.html#mongodb-outbound-gateway

更新

但我不知道要为插入消息有效负载的函数设置什么参数......因为在 ServiceActivator 中没有消息的引用

哦!我懂了。那是一个错误。我们无法从该上下文访问消息。请就此事提出JIRA:https ://jira.spring.io/projects/INT/

同时,作为一种解决方法,我建议您编写一个带有注入的自定义 POJO,MongoOperations然后您可以针对requestMessage.

JIRA 在这里:https ://jira.spring.io/browse/INT-4570


推荐阅读