Reputation: 23140
In a Corda flow, you can initiate a FlowSession
with a counterparty to send and receive data.
Can a node initiate a FlowSession
with themselves?
Upvotes: 0
Views: 323
Reputation: 21
Since Corda 4 this will throw an exception with message:
Do not provide flow sessions for the local node. FinalityFlow will record the notarised transaction locally.
Upvotes: 2
Reputation: 23140
Yes, this is completely fine. For example, the following would work:
@InitiatingFlow
@StartableByRPC
class Initiator : FlowLogic<Unit>() {
override val progressTracker = ProgressTracker()
@Suspendable
override fun call() {
val selfSession = initiateFlow(ourIdentity)
selfSession.send("It's me!")
}
}
@InitiatedBy(Initiator::class)
class Responder(val counterpartySession: FlowSession) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
logger.info(counterpartySession.receive<String>().unwrap { it })
}
}
Upvotes: 2