kotlin - ReceiveAll() 在 Corda 中的应用是什么?如何实施?
问题描述
有没有实现 sendAll() 和 receiveAll() 的示例?
接收所有(接收类型:类,会话:列表):列表<UntrustworthyData>
在文档中它说:从传入列表中指定的所有FlowSession对象接收。接收的类型必须相同。
它是否在响应程序流中使用?如果是这样,如何在receiveAll()中输入所需的会话作为列表?
解决方案
receiveAll() & sendAll() 实际上是 4.5 版本的性能升级。
这里举两个例子:
- 如果您想从 A 向 B/C 发送一条启动新会话的消息,您将对 B 和 C 使用 initialFlow,然后从 A 方执行sendAll()。在 B 和 C 的响应者端,您将做一个简单的接收。
- 如果您想在 A 方中接收来自 B 和 C 的并行消息(例如在建立会话之后),您可以从 B 和 C 执行普通发送,并从 A执行receiveAll() 。
发起人流程:
@InitiatingFlow
@StartableByRPC
class sendAllReceiveAllExampleFlow(private val itemToBeSent : String) : FlowLogic<String>(){
@Suspendable
override fun call() : String {
val counterParty1 = serviceHub.identityService.partiesFromName("PartyB",false).single()
val counterParty2 = serviceHub.identityService.partiesFromName("PartyC",false).single()
val counterPartySession1 = initiateFlow(counterParty1)
val counterPartySession2 = initiateFlow(counterParty2)
sendAll(itemToBeSent, setOf(counterPartySession1,counterPartySession2))
val receivedBack= receiveAll(String::class.java,listOf(counterPartySession1,
counterPartySession2)).map { it.unwrap { it } }
return "receivedBack :" + receivedBack.toString()
}
}
响应流程:
class SendAllReceiveAllResponder(private val counterSessionList : FlowSession): FlowLogic<Unit>(){
@Suspendable
override fun call(){
println("Inside Responder ")
val receivedString = counterSessionList.receive<String>().unwrap { it }
println("PayLoad Received at Responder = "+ receivedString)
counterSessionList.send(receivedString + ourIdentity.name.organisation)
}
}
案例场景来源:CordaLedger-Slack
推荐阅读
- c++ - 如何正确销毁从另一个线程运行的窗口?
- android - DialogFragment 完成后调用片段
- matlab - 如何去除这张带有形态学的照片中的图像噪点,同时使背景变白,同时又不会过多地降低文本的可读性?
- .net - 在 .net 核心中找不到 RIPEMD160
- gnuplot - 使用 Gnuplot 绘图时更改字体
- android-testing - 抛出 NullPointerException:该片段已在测试中从 FragmentManager 中删除
- sqlite - sql重复,而一个值在第1列中出现一次,在第2列中出现一次
- reactjs - Axios 在刷新时发出 2 个请求
- angular - 为什么我需要在按钮上单击 2 次才能让事件发生?
- c - struct inotify_event *event=(struct inotify_event*)&buffer[i]