Пример #1
0
func (t *Transport) subscribe(channel chan *api.Message) {
	conn, _ := t.getConnection() // todo handle messages better
	defer conn.Close()

	psc := pubsub.NewSubClient(conn)
	subClient := psc.Subscribe(t.InputBinding)
	log.Debugf("Processor subscribing to: %s", subClient)
	defer psc.Unsubscribe(t.InputBinding)

	for {
		resp := psc.Receive()
		//log.Debugln("after: ", resp)

		if resp.Err != nil {
			channel <- api.NewMessageFromRawBytes([]byte(resp.Err.Error()))
		} else {
			channel <- api.NewMessageFromRawBytes([]byte(resp.Message))
		}
	}
}
Пример #2
0
func (t *Transport) pop(channel chan *api.Message) {
	conn, _ := t.getConnection()
	defer conn.Close()

	for {
		content, err := conn.Cmd("BRPOP", t.InputBinding, 0).List()
		if err != nil {
			log.Errorf("Cannot BRPOP on '%v': %v", t.InputBinding, err)
		} else {
			channel <- api.NewMessageFromRawBytes([]byte(content[1]))
		}
	}
}