Listening to events -fabric client java
Mark Lewis
If you just want to get chaincode events, you would be better to just listen directly for chaincode events:
The Fabric Gateway client API provides by far the most efficient Java client implementation of both block and chaincode eventing. I would encourage you to avoid using fabric-sdk-java and prefer one of the high-level APIs above depending on the version of Fabric you are targeting. If you really must use the low-level legacy SDK for some reason, it provides chaincode event listening with Channel.registerChaincodeEventListener(). If you want to do the work yourself of extracting chaincode events from block events using the low-level legacy SDK, the block events you receive from fabric-sdk-java are the same as the ones surfaced by fabric-gateway-java, and you can listen for them using Channel.registerBlockListener(). Just be aware that you may receive duplicate or out-of-order events using fabric-sdk-java. fabric-sdk-java provides very weak support for replay of events. The recommended approach is to create a new channel, remove all the peers and then re-add them to the channel with their peer options modified to specify an event start block. If you want to pick apart how fabric-gateway-java does this on top of fabric-sdk-java, the code is here: https://github.com/hyperledger/fabric-gateway-java/blob/00afa0c6a376feea492b9d9390ae9415b404289d/src/main/java/org/hyperledger/fabric/gateway/impl/event/ReplayListenerSession.java#L31-L71 |
||||
|
||||
Matthew White
Hello – yes I’ve got an example of that… somewhere…
I’ll push it a github repo as it’s a useful example
Thanks Matthew
From: fabric@... <fabric@...>
On Behalf Of jeff.jo95z@...
Sent: 25 October 2022 10:05 To: fabric@... Subject: [EXTERNAL] [Hyperledger Fabric] Listening to events -fabric client java
Hi, How to subscribe to block events in fabric client (java)? I was looking for an equivalent of this in fabric client: Consumer<BlockEvent> blockListener = blockEvent -> blockListenerProcess(); networkObj. addBlockListener(startBlockNumber, ZjQcmQRYFpfptBannerStart
ZjQcmQRYFpfptBannerEnd Hi, blockEvent.getTransactionEvents() for (BlockEvent.TransactionEvent tEvent : transEvents) tEvent.getTransactionActionInfo(0).getEvent().getEventName()
Unless otherwise stated above:
IBM United Kingdom Limited Registered in England and Wales with number 741598 Registered office: PO Box 41, North Harbour, Portsmouth, Hants. PO6 3AU |
||||
|
||||
jeff.jo95z@...
Hi, blockEvent.getTransactionEvents() for (BlockEvent.TransactionEvent tEvent : transEvents) tEvent.getTransactionActionInfo(0).getEvent().getEventName()
|
||||
|