Пример #1
0
// FormatMessage formats a message as a string, just the body by default or
// the full message (with properties etc.) if "-full" flag is set.
func FormatMessage(m amqp.Message) string {
	if *Full {
		return fmt.Sprintf("%#v", m)
	} else {
		return fmt.Sprintf("%#v", m.Body())
	}
}
Пример #2
0
// Send sends a amqp.Message over a Link.
// Returns a Delivery that can be use to determine the outcome of the message.
func (link Link) Send(m amqp.Message) (Delivery, error) {
	if !link.IsSender() {
		return Delivery{}, internal.Errorf("attempt to send message on receiving link")
	}
	delivery := link.Delivery(tags.Next())
	bytes, err := m.Encode(nil)
	if err != nil {
		return Delivery{}, internal.Errorf("cannot send mesage %s", err)
	}
	result := link.SendBytes(bytes)
	link.Advance()
	if result != len(bytes) {
		if result < 0 {
			return delivery, internal.Errorf("send failed %v", internal.PnErrorCode(result))
		} else {
			return delivery, internal.Errorf("send incomplete %v of %v", result, len(bytes))
		}
	}
	if link.RemoteSndSettleMode() == SndSettled {
		delivery.Settle()
	}
	return delivery, nil
}