In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to use Eventeum to bridge the back-end micro service and the Ethernet Square intelligent contract". In the daily operation, it is believed that many people have doubts about how to use Eventeum to bridge the back-end micro service and the Ethernet Square intelligent contract. The editor consulted all kinds of materials and sorted out a simple and useful operation method. I hope it will be helpful for you to answer the question of "how to use Eventeum to bridge the back-end microservice and the Ethernet Square intelligent contract"! Next, please follow the editor to study!
1. What is Eventeum
Eventeum is an ethernet event monitoring service that provides bridging between intelligent contracts and middleware layers. Eventeum supports dynamic subscription to Ethernet Fong events. When the Ethernet Fong intelligent contract event is triggered, messages containing event details will be broadcast to the message bus (such as Kafka or RabbitMQ) and then utilized by the back-end service.
The main features of Eventeum include:
Dynamically configurable
Applications can make use of the REST api provided by Eventeum to dynamically subscribe or unsubscribe to ethernet intelligent contract events.
High availability
Eventeum instances communicate with each other to ensure that all instances subscribe to the same set of Ethernet Square intelligent contract events.
Elasticity
The node failure can be detected automatically, and the subscription can continue from the block at the time of failure when the node resumes work.
Bifurcation fault tolerance
Eventeum can configure the number of chunks required for event "acknowledgement". If a block chain bifurcation occurs during this period, Eventeum will broadcast a message to the network so that your back-end service can respond to the bifurcation event in a timely manner.
2. Deploy Eventeum
Eventeum currently supports three broadcast mechanisms:
Kafka
HTTP Post
RabbitMQ
In this tutorial, we will use Kafka.
The prerequisites for deploying Kafka are as follows:
Java8
Maven
Mongo
Kafka
Zookeeper
Ethereum Node
Docker (optional)
Docker is optional, but I recommend using the docker suite, which contains most of the above dependencies, except that you need to install Java8 and Maven first.
First of all, refer to the docker official website documentation to install Docker and Docker-compose.
Then clone the ethersquare Eventeum software library:
$git clone https://github.com/ConsenSys/eventeum.git
After checking out the Eventeum code, enter the project directory:
$cd / path/to/eventeum/
Compile, test, and package the Eventeum project:
$mvn clean package
Docker suite for integrated installation of Eventeum:
$cd server$ docker-compose-f docker-compose.yml build$ docker-compose-f docker-compose.yml up3, test Eventeum
To test Eventeum, we need to deploy a sample smart contract on the local Parity node (the ethersquare node automatically installed by Eventeum), and then subscribe to a smart contract event to broadcast over Kafka.
Let's deploy the CrudApp.sol contract first, using Remix IDE and Metamask.
Open Remix IDE and add a CrudApp.sol contract
Select the solc compiler version required for the contract (we use 0.4.23), and then compile the contract
Select node Localhost:8545 on Metamask
In Remix IDE, switch to the Run options page, then select the web3 provider in the current environment and deploy
Now, the contract has been deployed to the local Parity Ethernet Fong development node.
4. Register intelligent contract events
Now we need to register the events in Tai Tai Fong so that Eventeum can monitor these events and broadcast them. Eventeum provides REST api, and here's how to use this API to register smart contract events.
Registered contract event
URL: / api/rest/v1/event-filter
Method: POST
{"id": "event-identifier", "contractAddress": "0x1fbBeeE6eC2B7B095fE3c5A572551b1e260Af4d2", "eventSpecification": {"eventName": "TestEvent", "indexedParameterDefinitions": [{"position": 0, "type": "UINT256"}, {"position": 1, "type": "ADDRESS"}] "nonIndexedParameterDefinitions": [{"position": 2, "type": "BYTES32"}, {"position": 3, "type": "STRING"}]}, "correlationIdStrategy": {"type": "NON_INDEXED_PARAMETER", "parameterIndex": 0}}
For simplicity, we use curl to call the above API to register the specified ethernet square smart contract event:
Curl-X POST\ http://localhost:8060/api/rest/v1/event-filter\-H 'Cache-Control: no-cache'\-H 'Content-Type: application/json'\-H 'Postman-Token: 616712a3murbf11Mub bf5lub4acMeib82835779d51'-d'{"id": "Country", "contractAddress": "ENTER_YOUR_CONTRACT_ADDRESS_CHECK_IN_REMIX", "eventSpecification": {"eventName": "CountryEvent" "nonIndexedParameterDefinitions": [{"position": 0, "type": "STRING"}, {"position": 1, "type": "STRING"}, {"position": 2, "type": "UINT256"}]}'
After the registration is successful, you can get the ID in the response. Now let's call the contract method to trigger the CountryEvent event. To do this, we continue to use Remix IDE:
Now let's pass parameters ("USA", "Elizabeth Warren", 327946410) to the insert method, and if everything is all right, you can see the transaction in the Docker terminal.
5. Subscribe to NodeJS service in Eventeum service
Now let's use the NodeJS service to subscribe to the Kafka event pushed by Eventuem. The steps are as follows:
Mkdir watchercd watchernpm initnpm installnpm i kafka-node (Kafka-nodejs client) touch index.js
Add the following code to index.js:
Var kafka = require ('kafka-node') const client = new kafka.KafkaClient ({kafkaHost:' localhost:9092'}); var kafka = require ('kafka-node'); Consumer = kafka.Consumer,consumer = new Consumer (client, [{topic:' contract-events', partition: 0}], {autoCommit: false}); consumer.on ('message', function (message) {console.log (message);})
You can run as follows:
Nodejs index.js
As you can see, the theme we use is Eventeum's built-in contract-events. Use the following command to view all built-in Kafka topics for Eventeum:
Bin/kafka-topics.sh-list-zookeeper localhost:2181
The results are as follows:
_ _ consumer_offsetsblock-eventscontract-eventsfilter-eventsfilter-events-dlteventeumfilter-events-erreventeumfilter-eventsnull at this point, the study on "how to use Eventeum to bridge back-end microservices and Ethernet Square intelligent contract" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.