예제 #1
0
// Receive will reveive a message from the queue. may be blocked if there is no message in queue.
func (q *Queue) Receive(target interface{}) error {
	if !q.beginReceive {
		q.recvChan = make(chan ([]byte), defaultRecvChanLen)
		go q.keepReceivingFromQueue()
		q.beginReceive = true
	}

	if q.recvChan == nil {
		return errors.New("Message Queue Has Not Been Initialized.")
	}

	msg, ok := <-q.recvChan

	if !ok {
		return errors.New("Message Queue Has Been Closed.")
	}

	strMsg := string(msg)
	err := serializer.String2Struct(strMsg, target)
	if err != nil {
		return err
	}

	return nil

}
예제 #2
0
func (q *Queue) Receive(topic string, target interface{}) error {
	conn, err := redispool.GetClient(q.redishost)
	if err != nil {
		return err
	}
	_, err = conn.Do("SUBSCRIBE", topic)
	if err != nil {
		return err
	}

	result, err := conn.Receive()
	if err != nil {
		return err
	}

	strMsg := string(result.([]interface{})[2].([]byte))

	err = serializer.String2Struct(strMsg, target)
	if err != nil {
		return err
	}

	return nil

}
예제 #3
0
func (mgr *Manager) GetStatus(id uint64) (*Status, error) {
	key := OnlineStatusKeyPrefix + strconv.FormatUint(id, 10)
	conn, err := redispool.GetClient(mgr.redishost)
	if err != nil {
		return nil, err
	}

	status := &Status{}
	// get status from redis
	bufferStr, err := redis.String(conn.Do("GET", key))
	if err != nil {
		return nil, err
	}
	err = serializer.String2Struct(bufferStr, status)
	if err != nil {
		return nil, err
	}

	return status, nil
}