예제 #1
0
func (q *Queue) Send(topic string, msg interface{}) error {
	conn, err := redispool.GetClient(q.redishost)
	if err != nil {
		return err
	}

	msgStr, err := serializer.Struct2String(msg)
	if err != nil {
		return err
	}

	_, err = conn.Do("PUBLISH", topic, msgStr)
	if err != nil {
		return err
	}

	return nil
}
예제 #2
0
// Send will send a message to the queue.
func (q *Queue) Send(msg interface{}) error {
	if q.ch == nil {
		return errors.New("Message Queue Not Initialzed.")
	}
	msgStr, err := serializer.Struct2String(msg)
	if err != nil {
		return err
	}
	err = q.ch.Publish(
		"",           // exchange
		q.queue.Name, // routing key
		false,        // mandatory
		false,
		amqp.Publishing{
			DeliveryMode: amqp.Persistent,
			ContentType:  "text/plain",
			Body:         []byte(msgStr),
		})

	return nil
}
예제 #3
0
func (mgr *Manager) GetOnline(id uint64, status Status) error {
	key := OnlineStatusKeyPrefix + strconv.FormatUint(id, 10)
	conn, err := redispool.GetClient(mgr.redishost)
	if err != nil {
		return err
	}
	// serialize and store the device's online status info in redis
	bufferStr, err := serializer.Struct2String(status)
	if err != nil {
		return err
	}
	_, err = conn.Do("SET", key, bufferStr)
	if err != nil {
		return err
	}
	_, err = conn.Do("EXPIRE", key, status.HeartbeatInterval+status.HeartbeatInterval/2)
	if err != nil {
		return err
	}

	return nil
}