Пример #1
0
func (ms *MessageStore) AddMessage(msg *amqp.Message, queues []string) (map[string][]*amqp.QueueMessage, error) {
	msgs := make([]*amqp.TxMessage, 0, len(queues))
	for _, q := range queues {
		msgs = append(msgs, amqp.NewTxMessage(msg, q))
	}
	return ms.AddTxMessages(msgs)
}
Пример #2
0
func (channel *Channel) handleContentBody(frame *amqp.WireFrame) *amqp.AMQPError {
	if channel.currentMessage == nil {
		return amqp.NewSoftError(500, "Unexpected content body frame. No method content-having method called yet!", 0, 0)
	}
	if channel.currentMessage.Header == nil {
		return amqp.NewSoftError(500, "Unexpected content body frame! No header yet", 0, 0)
	}
	channel.currentMessage.Payload = append(channel.currentMessage.Payload, frame)
	// TODO: store this on message
	var size = uint64(0)
	for _, body := range channel.currentMessage.Payload {
		size += uint64(len(body.Payload))
	}
	if size < channel.currentMessage.Header.ContentBodySize {
		return nil
	}

	// We have the whole contents, let's publish!
	defer stats.RecordHisto(channel.statRoute, stats.Start())
	var server = channel.server
	var message = channel.currentMessage

	exchange, _ := server.exchanges[message.Method.Exchange]

	if channel.txMode {
		// TxMode, add the messages to a list
		queues, err := exchange.QueuesForPublish(channel.currentMessage)
		if err != nil {
			return err
		}

		channel.txLock.Lock()
		for queueName, _ := range queues {
			var txmsg = amqp.NewTxMessage(message, queueName)
			channel.txMessages = append(channel.txMessages, txmsg)
		}
		channel.txLock.Unlock()
	} else {
		// Normal mode, publish directly
		returnMethod, amqpErr := server.publish(exchange, channel.currentMessage)
		if amqpErr != nil {
			channel.currentMessage = nil
			return amqpErr
		}
		if returnMethod != nil {
			channel.SendContent(returnMethod, channel.currentMessage)
		}
	}

	channel.currentMessage = nil
	return nil
}