对方在意外的时间发送了会话拒绝消息,消息为无法建立会话

时间:2018-08-24 10:27:37

标签: database state h2 default corda

我的问题是,当我创建第二种状态时,Corda会引发异常。这里是例外:“ message”:“ net.corda.core.flows.UnexpectedFlowEndException:对方在意外的时间发送了会话拒绝消息,并显示消息无法建立会话。但是第一状态可以存储在Corda的默认数据库中。

这很奇怪。

first state:[
  {
    "foud_name": "23",
    "financing_name":"23",
    "financing_project":"23",
    "company_name":"23",
    "data_producer":"23",
    "attachment_name":"23",
    "attachment_type":"23",
    "attachment_id":"23"
  }
]

当我存储第二个时,它会引发异常:

{
  "timestamp": "2018-08-24T09:47:02.654+0000",
  "status": 500,
  "error": "Internal Server Error",
  "message": "net.corda.core.flows.UnexpectedFlowEndException: Counterparty sent session rejection message at unexpected time with message Unable to establish session",
  "path": "/api/v1/resarch-attachment"
}

1 个答案:

答案 0 :(得分:0)

此错误消息表明:

  • 作为流程的一部分,您正在向交易对手发送消息
  • 交易对方已注册了一个响应流,以对发送消息的流进行响应,但目前不希望收到消息

有几种可能的原因。响应流可能已经结束,或者此时可能不希望收到消息。

您说错误消息仅第二次发生。有了我的详细信息,我假设您的启动流程正在尝试使交易对手多次调用响应流程。像这样:

@InitiatingFlow
@StartableByRPC
class InitiatorFlow(val counterparty: Party) : FlowLogic<Unit>() {
    @Suspendable
    override fun call() {
        val counterpartySession = initiateFlow(counterparty)

        (0..99).forEach { 
            counterpartySession.send("My payload.")
        }
    }
}

@InitiatedBy(InitiatorFlow::class)
class ResponderFlow(val counterpartySession: FlowSession) : FlowLogic<Unit>() {
    @Suspendable
    override fun call() {
        counterpartySession.receive<String>()
    }
}

这将不起作用。启动启动流时,将为其指定流ID。与交易对手通信时使用此ID来告诉他们使用哪个响应流:

  • 如果交易对手从未从具有此ID的流中收到消息,它将创建响应流的新实例
  • 如果交易对手之前已从该ID的流中接收到消息,它将继续使用该实例
    • 如果此流实例已完成运行,则不会创建新实例,而是假设发生了错误,并给出您在上面看到的错误消息

相反,您需要使用子流为与交易对手的每次通信创建一个新的流ID。像这样:

@InitiatingFlow
@StartableByRPC
class InitiatorFlow(val counterparty: Party) : FlowLogic<Unit>() {
    @Suspendable
    override fun call() {
        (0..99).forEach {
            subFlow(SendMessageFlow(counterparty))
        }
    }
}

@InitiatingFlow
class SendMessageFlow(val counterparty: Party) : FlowLogic<Unit>() {
    @Suspendable
    override fun call() {
        val counterpartySession = initiateFlow(counterparty)
        counterpartySession.send("My payload.")
    }
}

@InitiatedBy(SendMessageFlow::class)
class ResponderFlow(val counterpartySession: FlowSession) : FlowLogic<Unit>() {
    @Suspendable
    override fun call() {
        counterpartySession.receive<String>()
    }
}