All Products
Search
Document Center

Blockchain as a Service:Send Blockchain Events to MQ

Last Updated:Aug 01, 2022

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. The specific operations are as follows.

    1. In the left-side navigation pane, click Instances.

    2. In the top navigation bar, select a region such as China (Hangzhou).

    3. Find the target instance you need to query in the instance list. Click More in its Action column, and select Message query in the pop-up drop-down menu.

    Integrate Alibaba Cloud BaaS with RocketMQ

Sample successful output

Data pushed to blockchain with transaction 701c7006f26aed8457273a00bbfcc8cea4d75eac958996e07837036ea7e2fdac
{ id: '701c7006f26aed8457273a00bbfcc8cea4d75eac958996e07837036ea7e2fdac',
  status: '200',
  events:
   [ { type: 'Contract',
       platform: 'Fabric',
       instance_id: 'csi-e2ehmfqasth-bcw7tzao2dzeo',
       network: '',
       id: '',
       name: 'event-create-task',
       content: 'eyJuY...TAz' }
Data pushed to blockchain with transaction 60a06a189415db587b49cbf91b46467bce1ea16490b19f6dfc8d520aa31240bc
{ id: '60a06a189415db587b49cbf91b46467bce1ea16490b19f6dfc8d520aa31240bc',
  status: '200',
  events:
   [ { type: 'Contract',
       platform: 'Fabric',
       instance_id: 'csi-e2ehmfqasth-bcw7tzao2dzeo',
       network: '',
       id: '',
       name: 'event-task-finished',
       content: 'eyJuY...p7In0=' } ],
  data: 'eyJu...In0=' }
Data pushed to blockchain with transaction 7810e0496a1c91a16102736b00a6f26da0baa42874a907fff26bff1b7eb3bf27
{ id: '7810e0496a1c91a16102736b00a6f26da0baa42874a907fff26bff1b7eb3bf27',
  status: '200',
  events: [],
  data: 'eyJu...nIn0=' }