diff --git a/redis/subscribers.go b/redis/subscribers.go index 0a6a53a..88e5a12 100644 --- a/redis/subscribers.go +++ b/redis/subscribers.go @@ -2,7 +2,10 @@ package redis import ( "context" + "encoding/json" + "fmt" + "git.loafle.net/commons_go/logging" uch "git.loafle.net/commons_go/util/channel" ofs "git.loafle.net/overflow/overflow_subscriber" "github.com/garyburd/redigo/redis" @@ -75,7 +78,12 @@ func (s *subscribers) listenSubscriptions() { switch v := s.conn.Receive().(type) { case redis.Message: if h, ok := s.subHandlers[v.Channel]; ok { - h.OnSubscribe(v.Channel, v.Data) + var message ofs.SubscribeMessage + if err := json.Unmarshal(v.Data, &message); nil != err { + logging.Logger.Error(fmt.Sprintf("Subscriber: Unmarshal error:%v", err)) + break + } + h.OnSubscribe(v.Channel, message) } break case redis.Subscription: diff --git a/subscriber_handler.go b/subscriber_handler.go index b8b6b5d..b4cb9ed 100644 --- a/subscriber_handler.go +++ b/subscriber_handler.go @@ -2,5 +2,5 @@ package overflow_subscriber type SubscriberHandler interface { GetChannel() string - OnSubscribe(channel string, payload []byte) + OnSubscribe(channel string, message SubscribeMessage) } diff --git a/subscriber_handlers.go b/subscriber_handlers.go index 7f10b50..540bc24 100644 --- a/subscriber_handlers.go +++ b/subscriber_handlers.go @@ -7,5 +7,5 @@ type SubscriberHandlers struct { func (h *SubscriberHandlers) GetChannel() string { return h.Channel } -func (h *SubscriberHandlers) OnSubscribe(channel string, payload []byte) { +func (h *SubscriberHandlers) OnSubscribe(channel string, message SubscribeMessage) { }