编译源代码
- 创建代码目录
mkdir -p /project/eventplugin/
- 下载eventplugin源码
cd /project/eventplugin/
git clone https://github.com/tronprotocol/event-plugin.git
- 编译eventplugin项目
cd eventplugin
./gradlew build
- 查看编译好的jar包
cd /build/libs
部署MongoDB
配置
event.subscribe = {
path = "/project/eventplugin/build/plugins/plugin-mongodb-1.0.0.zip" // absolute path of plugin
server = "127.0.0.1:27017" // target server address to receive event triggers
dbconfig = "eventlog|tron|123456" // dbname|username|password
topics = [
{
triggerName = "block" // block trigger, the value can't be modified
enable = false
topic = "block" // plugin topic, the value could be modified
},
{
triggerName = "transaction"
enable = false
topic = "transaction"
},
{
triggerName = "contractevent"
enable = true
topic = "contractevent"
},
{
triggerName = "contractlog"
enable = true
topic = "contractlog"
},
{
triggerName = "solidity" // solidity block event trigger, the value can't be modified
enable = true // the default value is true
topic = "solidity"
},
{
triggerName = "solidityevent"
enable = false
topic = "solidityevent"
},
{
triggerName = "soliditylog"
enable = false
topic = "soliditylog"
}
]
filter = {
fromblock = "" // the value could be "", "earliest" or a specified block number as the beginning of the queried range
toblock = "" // the value could be "", "latest" or a specified block number as end of the queried range
contractAddress = [
"" // contract address you want to subscribe, if it's set to "", you will receive contract logs/events with any contract address.
]
contractTopic = [
"" // contract topic you want to subscribe, if it's set to "", you will receive contract logs/events with any contract topic.
]
}
}
字段解析
- path: “plugin-kafka-1.0.0.zip” 或 "plugin-mongodb-1.0.0.zip"的绝对路径
- server: 服务器地址+端口号(mongodb的)
- dbconfig: mongodb的配置,按例子中的来
- topics: 目前支持四种事件类型 block, transaction, contract log and contract event
- triggerName: 触发类型,可以修改
- enable: fasle就是禁用,true开启
- topic: mongodb接收事件的集合
部署MongoDB
安装
mkdir /project/soft
cd /project/soft
curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.4.tgz
tar zxvf mongodb-linux-x86_64-4.0.4.tgz
mv mongodb-linux-x86_64-4.0.4 mongodb
设置环境变量
export MONGOPATH= /project/soft/mongodb/
export PATH=$PATH:$MONGOPATH/bin
mongodb配置
mkdir -p /project/soft/mongodb/{log,data}
cd /project/soft/mongodb/log/ && touch mongodb.log && cd
vim mgdb.conf
mgdb.conf
dbpath=/project/soft/mongodb/data
logpath=/project/soft/mongodb/log/mongodb.log
port=27017
logappend=true
fork=true
bind_ip=0.0.0.0
auth=true
wiredTigerCacheSizeGB=2
启动mongodb
启动mongodb
mongod --config ./mgdb.conf &
创建管理员命令
mongo
use admin
db.createUser({user:"root",pwd:"hVvTb8ZHKnO3r555",roles:[{role:"root",db:"admin"}]})
创建db eventlog和账户命令
db.auth("root", "hVvTb8ZHKnO3r555")
use eventlog
db.createUser({user:"tron",pwd:"123456",roles:[{role:"dbOwner",db:"eventlog"}]})
部署kafka插件
配置
event.subscribe = {
native = {
useNativeQueue = false// if true, use native message queue, else use event plugin.
bindport = 5555// bind port
sendqueuelength = 1000 //max length of send queue
}
path = "" // absolute path of plugin
server = "" // target server address to receive event triggers
# dbconfig="" // dbname|username|password
topics = [
{
triggerName = "block" // block trigger, the value can't be modified
enable = false
topic = "block" // plugin topic, the value could be modified
},
{
triggerName = "transaction"
enable = false
topic = "transaction"
},
{
triggerName = "contractevent"
enable = true
topic = "contractevent"
},
{
triggerName = "contractlog"
enable = true
topic = "contractlog"
},
{
triggerName = "solidity" // solidity block event trigger, the value can't be modified
enable = true // the default value is true
topic = "solidity"
},
{
triggerName = "solidityevent"
enable = false
topic = "solidityevent"
},
{
triggerName = "soliditylog"
enable = false
topic = "soliditylog"
}
]
filter = {
fromblock = "" // the value could be "", "earliest" or a specified block number as the beginning of the queried range
toblock = "" // the value could be "", "latest" or a specified block number as end of the queried range
contractAddress = [
"" // contract address you want to subscribe, if it's set to "", you will receive contract logs/events with any contract address.
]
contractTopic = [
"" // contract topic you want to subscribe, if it's set to "", you will receive contract logs/events with any contract topic.
]
}
}
安装kafka
mkdir /project/soft
cd /project/soft
wget http://archive.apache.org/dist/kafka/0.10.2.2/kafka_2.10-0.10.2.2.tgz
tar -xzvf kafka_2.10-0.10.2.2.tgz
mv kafka_2.10-0.10.2.2 kafka
add "export PATH=$PATH:/project/soft/kafka/bin" to end of /etc/profile
source /etc/profile
创建topic
kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic block
kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic transaction
kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic contractlog
kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic contractevent
kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic solidity
kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic solidityevent
kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic soliditylog
启动消费者
kafka-console-consumer.sh --zookeeper localhost:2181 --topic block
kafka-console-consumer.sh --zookeeper localhost:2181 --topic transaction
kafka-console-consumer.sh --zookeeper localhost:2181 --topic contractlog
kafka-console-consumer.sh --zookeeper localhost:2181 --topic contractevent
kafka-console-consumer.sh --zookeeper localhost:2181 --topic solidity
kafka-console-consumer.sh --zookeeper localhost:2181 --topic solidityevent
kafka-console-consumer.sh --zookeeper localhost:2181 --topic soliditylog
启动节点
java -jar FullNode.jar -c config.conf --es
参考文档
https://cn.developers.tron.network/docs/tron%E4%BA%8B%E4%BB%B6%E6%8F%92%E4%BB%B6mongodb
https://github.com/tronprotocol/event-plugin