-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZMQ.go
More file actions
37 lines (31 loc) · 752 Bytes
/
ZMQ.go
File metadata and controls
37 lines (31 loc) · 752 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"context"
"encoding/json"
"log"
"github.com/zeromq/goczmq"
)
type ZeroMQOutboundAdapter struct {
Publisher *goczmq.Sock
}
func NewZeroMQOutboundAdapter() (*ZeroMQOutboundAdapter, error) {
adapter := &ZeroMQOutboundAdapter{}
var err error
adapter.Publisher, err = goczmq.NewPub("tcp://127.0.0.1:5555")
if err != nil {
log.Printf("error creating 0MQ publisher: %v\n", err)
return nil, err
}
return adapter, nil
}
func (z *ZeroMQOutboundAdapter) Close() {
z.Publisher.Destroy()
}
func (z *ZeroMQOutboundAdapter) Write(ctx context.Context, msg Message) error {
validatorJSON, err := json.Marshal(msg.Payload.(Validator))
if err != nil {
return err
}
_, err = z.Publisher.Write(validatorJSON)
return err
}