net.corda.core.flows.UnexpectedFlowEndException:尝试访问已结束的会话 SessionId(toLong=8223329095323268490),缓冲区为空
net.corda.core.flows.UnexpectedFlowEndException: Tried to access ended session SessionId(toLong=8223329095323268490) with empty buffer
class Initiator(private val notificationObject: NotificationModel, private val counterParty: Party) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
val counterPartySession = initiateFlow(counterParty)
val counterPartyData = counterPartySession.sendAndReceive<NotificationModel>(notificationObject)
counterPartyData.unwrap { msg ->
assert(msg.notification_data == notificationObject.notification_data)
}
}
}
sendAndReceive 出现问题。感谢任何形式的帮助。
感谢您提供代码。看起来 Acceptor
没有向 Initiator
发回消息?
您的 Initiator
调用 sendAndReceive<>
,这意味着它会想要从 Acceptor
返回一些东西。在这种情况下,Acceptor
没有发回响应,所以我们看到了 UnexpectedEndOfFLowException
(因为 Initiator
期望返回一些东西但没有得到它)。
我怀疑您想要添加一行以将 NotificationModel
发回:
@InitiatedBy(Initiator::class)
class Acceptor(private val counterpartySession: FlowSession) : FlowLogic<Unit>() {
@Suspendable override fun call() {
val counterPartyData = counterpartySession.receive<NotificationModel>()
counterPartyData.unwrap { msg -> //code goes here }
counterPartySession.send(/* some payload of type NotificationModel here */)
}
}
请参阅以下文档:https://docs.corda.net/api-flows.html#sendandreceive
或者,如果您不希望 Acceptor
返回响应,您可以在 Initiator
上调用 send
:https://docs.corda.net/api-flows.html#send
class Initiator(private val notificationObject: NotificationModel, private val counterParty: Party) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
val counterPartySession = initiateFlow(counterParty)
val counterPartyData = counterPartySession.sendAndReceive<NotificationModel>(notificationObject)
counterPartyData.unwrap { msg ->
assert(msg.notification_data == notificationObject.notification_data)
}
}
}
sendAndReceive 出现问题。感谢任何形式的帮助。
感谢您提供代码。看起来 Acceptor
没有向 Initiator
发回消息?
您的 Initiator
调用 sendAndReceive<>
,这意味着它会想要从 Acceptor
返回一些东西。在这种情况下,Acceptor
没有发回响应,所以我们看到了 UnexpectedEndOfFLowException
(因为 Initiator
期望返回一些东西但没有得到它)。
我怀疑您想要添加一行以将 NotificationModel
发回:
@InitiatedBy(Initiator::class)
class Acceptor(private val counterpartySession: FlowSession) : FlowLogic<Unit>() {
@Suspendable override fun call() {
val counterPartyData = counterpartySession.receive<NotificationModel>()
counterPartyData.unwrap { msg -> //code goes here }
counterPartySession.send(/* some payload of type NotificationModel here */)
}
}
请参阅以下文档:https://docs.corda.net/api-flows.html#sendandreceive
或者,如果您不希望 Acceptor
返回响应,您可以在 Initiator
上调用 send
:https://docs.corda.net/api-flows.html#send