func (c *conn) handlePublish(p *proto.Proto) error { tp := p.PubType() queue := p.Queue() routingKey := p.RoutingKey() message := p.Body if err := checkPublish(queue, routingKey, tp, message); err != nil { return c.protoError(http.StatusBadRequest, err.Error()) } msg, err := c.app.saveMsg(queue, routingKey, tp, message) if err != nil { return c.protoError(http.StatusInternalServerError, err.Error()) } q := c.app.qs.Get(queue) q.Push(msg) np := proto.NewPublishOKProto(strconv.FormatInt(msg.id, 10)) c.writeProto(np.P) return nil }
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 }