예제 #1
0
func (t *mockTransport) Respond(req message.Request, rsp message.Response) error {
	t.RLock()
	rspChan, ok := t.inflightReqs[req.Id()]
	t.RUnlock()

	// Make a copy of the response that does not preserve the Body (this is not preserved over the wire)
	rsp = rsp.Copy()
	rsp.SetBody(nil)

	if ok {
		select {
		case rspChan <- rsp:
			return nil
		case <-time.After(timeout):
			return transport.ErrTimeout
		}
	}
	return fmt.Errorf("No correlated request \"%s\" is in-flight", req.Id())
}
예제 #2
0
func (t *rabbitTransport) Respond(req message.Request, rsp message.Response) error {
	headers := rsp.Headers()
	headers["Content-Encoding"] = "response"

	timeout := time.NewTimer(respondTimeout)
	defer timeout.Stop()
	select {
	case <-t.Ready():
		timeout.Stop()
	case <-t.tomb.Dying():
		return tomb.ErrDying
	case <-timeout.C:
		return transport.ErrTimeout
	}

	return t.connection().Publish("", req.Headers()["X-Rabbit-ReplyTo"], amqp.Publishing{
		CorrelationId: rsp.Id(),
		Timestamp:     time.Now().UTC(),
		Body:          rsp.Payload(),
		Headers:       headersToTable(headers),
	})
}