예제 #1
0
파일: util.go 프로젝트: ChugR/qpid-proton
// 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{}, fmt.Errorf("attempt to send message on receiving link")
	}

	delivery := link.Delivery(nextTag())
	bytes, err := m.Encode(nil)
	if err != nil {
		return Delivery{}, fmt.Errorf("cannot send mesage %s", err)
	}
	result := link.SendBytes(bytes)
	link.Advance()
	if result != len(bytes) {
		if result < 0 {
			return delivery, fmt.Errorf("send failed %v", PnErrorCode(result))
		} else {
			return delivery, fmt.Errorf("send incomplete %v of %v", result, len(bytes))
		}
	}
	if link.RemoteSndSettleMode() == SndSettled {
		delivery.Settle()
	}
	return delivery, nil
}