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
| package pub
|
| import (
| "basic.com/pubsub/protomsg.git"
| "github.com/gogo/protobuf/proto"
| )
|
| type pubUtil struct {
| topic string
| publish func(string, []byte) error
| }
|
| var putil = pubUtil{}
|
| func InitPub(topic string, f func(string, []byte) error) {
| putil.topic = topic
| if f != nil {
| putil.publish = f
| }
| }
|
| func AddDbMessage(msg *protomsg.DbChangeMessage) {
| if putil.topic != "" && putil.publish != nil {
| bts, err := proto.Marshal(msg)
| if err == nil {
| putil.publish(putil.topic, bts)
| }
| }
| }
|
|