All Products
Search
Document Center

Send Blockchain Events to MQ

Last Updated: Jun 11, 2020

Prerequisites

  1. The cloud service integration module is installed for the blockchain instance, and RocketMQ integration is enabled.
  2. A RocketMQ instance is created. In this topic, instance “fabric-instance” is used as an example, and the message topic is “event”.
  3. Cloud service integration sample code is downloaded.
  4. Node.js v8.17.0 or later is installed.

Procedure

  1. In the Alibaba Cloud Blockchain as a Service (BaaS) console, create a message queue trigger for cloud service integration. For more information, see Configure a message queue trigger.
    1. Set the trigger event type to Tx.
    2. Fill in the information about the RocketMQ instance based on the help documentation.
  2. Deploy sample chaincode taskmgr to the channel by referring to Chaincode Deployment.
  3. Go to the blockchain2sms directory, modify the parameters in main.js based on comments, and fill in the REST API address, refresh token, channel name, and smart contract name. For more information, see Use REST APIs.
  4. Execute npm install to install dependent packages and node main.js to initiate a sample transaction.
  5. Log on to the RocketMQ console to query the messages pushed to the message queue.Integrate Alibaba Cloud BaaS with RocketMQ

Sample successful output

  1. Data pushed to blockchain with transaction 701c7006f26aed8457273a00bbfcc8cea4d75eac958996e07837036ea7e2fdac
  2. { id: '701c7006f26aed8457273a00bbfcc8cea4d75eac958996e07837036ea7e2fdac',
  3. status: '200',
  4. events:
  5. [ { type: 'Contract',
  6. platform: 'Fabric',
  7. instance_id: 'csi-e2ehmfqasth-bcw7tzao2dzeo',
  8. network: '',
  9. id: '',
  10. name: 'event-create-task',
  11. content: 'eyJuY...TAz' }
  12. Data pushed to blockchain with transaction 60a06a189415db587b49cbf91b46467bce1ea16490b19f6dfc8d520aa31240bc
  13. { id: '60a06a189415db587b49cbf91b46467bce1ea16490b19f6dfc8d520aa31240bc',
  14. status: '200',
  15. events:
  16. [ { type: 'Contract',
  17. platform: 'Fabric',
  18. instance_id: 'csi-e2ehmfqasth-bcw7tzao2dzeo',
  19. network: '',
  20. id: '',
  21. name: 'event-task-finished',
  22. content: 'eyJuY...p7In0=' } ],
  23. data: 'eyJu...In0=' }
  24. Data pushed to blockchain with transaction 7810e0496a1c91a16102736b00a6f26da0baa42874a907fff26bff1b7eb3bf27
  25. { id: '7810e0496a1c91a16102736b00a6f26da0baa42874a907fff26bff1b7eb3bf27',
  26. status: '200',
  27. events: [],
  28. data: 'eyJu...nIn0=' }