0
votes

I'm wondering how is possible to send notifications from the chaincode of a fabric network.

What I would like to do is send a notification to an external legacy system every time a new transaction is successfully committed to the ledger.

To achieve this I thought about two different ways:

  1. HTTP Request - Is possible to execute an http request directly from the chaincode? If yes, is it possible to send an http request to the endpoint of the legacy system to notify the transaction?
  2. Event - I understood that there is the possibility to create events in the chaincode. Is possible to listen these events without using the Fabric SDK (I can't integrate the SDK in the legacy system)?

What are your considerations about these two approaches? Do you have any suggestion?

1

1 Answers

0
votes

HTTP Request

Yes, this possible, but definitely not recommended. The chaincode is used to endorse transaction proposals, but one peer's endorsement of a transaction proposal does not necessarily mean that transaction itself will be committed. Sending the request from chaincode execution would be premature. You can read more about transaction flow here and here

Additionally, the chaincode is not necessarily (and not supposed to be) executed on only one peer. If you have the request being sent from the chaincode and you have 10 peers executing the chaincode, you're going to have 10 requests going to your legacy system.

Event

You can set custom events in the chaincode, but you won't need them as each sdk supports notification of transaction commitment. While I understand it is not reasonable to embed the sdk within your legacy service, the sdk is most likely the best place for you to listen for events.

Peer Channel Event Service

From 1.3 moving forward the peer will has a specific channel event service. I will not go into this as I have not used it yet and I'm assuming if your legacy system cannot integrate an sdk it most likely will not support making grpc calls against a peer service.

Solution

You will probably need to cobble together the HTTP Request and Event solutions. Have a separate service use the sdk to send transaction proposals and listen for notifications of transaction commitment. Once a transaction is committed, use this service to send a request to your legacy system's endpoint.