123456789101112131415161718192021222324252627282930313233 |
- package odbc
- import (
- "context"
- "git.wecise.com/wecise/odb-go/odb"
- "git.wecise.com/wecise/odb-go/odb/eventmsg"
- )
- func SubscribeTest(client odb.Client) {
- Subscribe(client, "CLASS_DATA_CHANGE:/")
- Subscribe(client, "META_DATA_CHANGE:/")
- }
- func Subscribe(client odb.Client, topic string) {
- sub := client.Subscribe(context.Background(), topic)
- go func() {
- defer func() {
- if err := sub.Unsubscribe(context.Background()); err != nil {
- log.Error(err)
- return
- }
- }()
- for m := range sub.Channel() {
- oem, err := eventmsg.FromMsgpack([]byte(m.Payload))
- if err != nil {
- log.Error(err)
- }
- string_message := oem.Data.String()
- log.Info(topic + " received " + topic + " message " + "\n" + string_message)
- }
- }()
- }
|