示例#1
0
func (c *conn) handleBind(p *proto.Proto) error {
	queue := p.Queue()
	routingKey := p.RoutingKey()

	if err := checkBind(queue, routingKey); err != nil {
		return c.protoError(http.StatusBadRequest, err.Error())
	}

	noAck := (p.Value(proto.NoAckStr) == "1")

	ch, ok := c.channels[queue]
	if !ok {
		q := c.app.qs.Get(queue)
		ch = newChannel(&connMsgPusher{c}, q, routingKey, noAck)
		c.channels[queue] = ch
	} else {
		ch.Reset(routingKey, noAck)
	}

	np := proto.NewBindOKProto(queue)

	c.writeProto(np.P)

	return nil
}