Skip to content
Snippets Groups Projects
Commit cc1f7db0 authored by Wolfgang Welz's avatar Wolfgang Welz
Browse files

Call the zmq send from a goroutine

parent 2d34a35d
Branches
Tags
No related merge requests found
...@@ -15,6 +15,7 @@ import ( ...@@ -15,6 +15,7 @@ import (
var PLUGIN = node.NewPlugin("ZeroMQ", configure, run) var PLUGIN = node.NewPlugin("ZeroMQ", configure, run)
var publisher *Publisher var publisher *Publisher
var emptyTag = strings.Repeat("9", 27)
// Configure the zeromq plugin // Configure the zeromq plugin
func configure(plugin *node.Plugin) { func configure(plugin *node.Plugin) {
...@@ -31,9 +32,12 @@ func configure(plugin *node.Plugin) { ...@@ -31,9 +32,12 @@ func configure(plugin *node.Plugin) {
// TODO: should be tangle.Events.TransactionStored // TODO: should be tangle.Events.TransactionStored
tangle.Events.TransactionSolid.Attach(events.NewClosure(func(tx *value_transaction.ValueTransaction) { tangle.Events.TransactionSolid.Attach(events.NewClosure(func(tx *value_transaction.ValueTransaction) {
if err := publishTx(tx); err != nil { // create goroutine for every event
plugin.LogFailure(err.Error()) go func() {
} if err := publishTx(tx); err != nil {
plugin.LogFailure(err.Error())
}
}()
})) }))
} }
...@@ -72,14 +76,13 @@ func publishTx(tx *value_transaction.ValueTransaction) error { ...@@ -72,14 +76,13 @@ func publishTx(tx *value_transaction.ValueTransaction) error {
trunk := tx.MetaTransaction.GetTrunkTransactionHash() trunk := tx.MetaTransaction.GetTrunkTransactionHash()
branch := tx.MetaTransaction.GetBranchTransactionHash() branch := tx.MetaTransaction.GetBranchTransactionHash()
stored := time.Now().Unix() stored := time.Now().Unix()
tag := strings.Repeat("9", 27) // use empty tag
messages := []string{ messages := []string{
"tx", // ZMQ event "tx", // ZMQ event
hash.ToString(), // Transaction hash hash.ToString(), // Transaction hash
address.ToString(), // Address address.ToString(), // Address
strconv.FormatInt(value, 10), // Value strconv.FormatInt(value, 10), // Value
tag, // Obsolete tag emptyTag, // Obsolete tag
strconv.FormatInt(timestamp, 10), // Timestamp strconv.FormatInt(timestamp, 10), // Timestamp
"0", // Index of the transaction in the bundle "0", // Index of the transaction in the bundle
"0", // Last transaction index of the bundle "0", // Last transaction index of the bundle
...@@ -87,7 +90,7 @@ func publishTx(tx *value_transaction.ValueTransaction) error { ...@@ -87,7 +90,7 @@ func publishTx(tx *value_transaction.ValueTransaction) error {
trunk.ToString(), // Trunk transaction hash trunk.ToString(), // Trunk transaction hash
branch.ToString(), // Branch transaction hash branch.ToString(), // Branch transaction hash
strconv.FormatInt(stored, 10), // Unix timestamp for when the transaction was received strconv.FormatInt(stored, 10), // Unix timestamp for when the transaction was received
tag, // Tag emptyTag, // Tag
} }
return publisher.Send(messages) return publisher.Send(messages)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment