【问题标题】:Counterparty sent session rejection message at unexpected time with message Unable to establish session交易对手在意外时间发送会话拒绝消息,并显示消息无法建立会话
【发布时间】:2019-01-30 19:39:48
【问题描述】:

我的问题是,当我创建第二个状态时,Corda 会引发异常。这里有一个例外:“消息”:“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"
}

【问题讨论】:

    标签: database state h2 default corda


    【解决方案1】:

    此错误消息表明:

    • 作为流程的一部分,您正在向对方发送消息
    • 对方已注册响应流以响应正在发送消息的流,但它不希望此时收到消息

    发生这种情况的原因有多种。响应流可能已经结束,或者此时可能不会收到消息。

    您说错误消息只发生第二次。根据我所掌握的详细信息,我假设您的启动流程正试图让交易对手多次调用响应流程。比如:

    @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>()
        }
    }
    

    【讨论】:

    • 嗨,我是第一次收到这条消息。我已经正确配置了响应者和发起者。我错过了什么吗?
    猜你喜欢
    • 2018-11-24
    • 1970-01-01
    • 1970-01-01
    • 2019-03-27
    • 2012-05-28
    • 2011-11-09
    • 2018-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多