//pub/sub channel message broker
pub/sub channel message broker
// pub / sub channel message broker
func MessageBroker()  {
  RedisConn , err := RedisConn()
  if err != nil {
    panic(err)
  }
  defer RedisConn.Close()
  PubSubConn = &redis.PubSubConn{Conn: RedisConn}
  PubSubConn.Subscribe("live")
  defer PubSubConn.Close()
  for {
    switch v := PubSubConn.Receive().(type) {
    case redis.Message:
      inform(v.Channel, string(v.Data))
      log.Printf("message received: %s: %s \n", v.Channel, string(v.Data))
    case redis.Subscription:
      log.Printf("subscription message: %s: %s %d\n", v.Channel, v.Kind, v.Count)
    case error:
      log.Fatal( v )
      return
    }
  }
}
func MessageBroker ( ) { RedisConn , err := RedisConn ( ) if err != nil { panic ( err ) } defer RedisConn . Close ( ) PubSubConn = & redis . PubSubConn { Conn : RedisConn } PubSubConn . Subscribe ( " " ) defer PubSubConn . Close ( ) for { switch v := PubSubConn . Receive ( ) . ( type ) { case redis . Message : inform ( v . Channel , string ( v . Data ) ) log . Printf ( " \n " , v . Channel , string ( v . Data ) ) case redis . Subscription : log . Printf ( " \n " , v . Channel , v . Kind , v . Count ) case error : log . Fatal ( v ) return } } }
pub/sub channel message broker
pub / sub channel message broker
//open redis connection //subscribe to pub/sub live channel