9 | 9 |
// RequestFunc may take information from a publisher request and put it into a
|
10 | 10 |
// request context. In Subscribers, RequestFuncs are executed prior to invoking
|
11 | 11 |
// the endpoint.
|
12 | |
type RequestFunc func(context.Context, *amqp.Publishing) context.Context
|
|
12 |
type RequestFunc func(context.Context, *amqp.Publishing, *amqp.Delivery) context.Context
|
13 | 13 |
|
14 | 14 |
// SubscriberResponseFunc may take information from a request context and use it to
|
15 | 15 |
// manipulate a Publisher. SubscriberResponseFuncs are only executed in
|
|
28 | 28 |
// SetPublishExchange returns a RequestFunc that sets the Exchange field
|
29 | 29 |
// of an AMQP Publish call.
|
30 | 30 |
func SetPublishExchange(publishExchange string) RequestFunc {
|
31 | |
return func(ctx context.Context, pub *amqp.Publishing) context.Context {
|
|
31 |
return func(ctx context.Context, pub *amqp.Publishing, _ *amqp.Delivery) context.Context {
|
32 | 32 |
return context.WithValue(ctx, ContextKeyExchange, publishExchange)
|
33 | 33 |
}
|
34 | 34 |
}
|
|
36 | 36 |
// SetPublishKey returns a RequestFunc that sets the Key field
|
37 | 37 |
// of an AMQP Publish call.
|
38 | 38 |
func SetPublishKey(publishKey string) RequestFunc {
|
39 | |
return func(ctx context.Context, pub *amqp.Publishing) context.Context {
|
|
39 |
return func(ctx context.Context, pub *amqp.Publishing, _ *amqp.Delivery) context.Context {
|
40 | 40 |
return context.WithValue(ctx, ContextKeyPublishKey, publishKey)
|
41 | 41 |
}
|
42 | 42 |
}
|
|
44 | 44 |
// SetPublishDeliveryMode sets the delivery mode of a Publishing.
|
45 | 45 |
// Please refer to AMQP delivery mode constants in the AMQP package.
|
46 | 46 |
func SetPublishDeliveryMode(dmode uint8) RequestFunc {
|
47 | |
return func(ctx context.Context, pub *amqp.Publishing) context.Context {
|
|
47 |
return func(ctx context.Context, pub *amqp.Publishing, _ *amqp.Delivery) context.Context {
|
48 | 48 |
pub.DeliveryMode = dmode
|
49 | 49 |
return ctx
|
50 | 50 |
}
|
|
56 | 56 |
// One example is the SingleNackRequeueErrorEncoder.
|
57 | 57 |
// It is designed to be used by Subscribers.
|
58 | 58 |
func SetNackSleepDuration(duration time.Duration) RequestFunc {
|
59 | |
return func(ctx context.Context, pub *amqp.Publishing) context.Context {
|
|
59 |
return func(ctx context.Context, pub *amqp.Publishing, _ *amqp.Delivery) context.Context {
|
60 | 60 |
return context.WithValue(ctx, ContextKeyNackSleepDuration, duration)
|
61 | 61 |
}
|
62 | 62 |
}
|
|
67 | 67 |
// a matching correlationId.
|
68 | 68 |
// It is designed to be used by Publishers.
|
69 | 69 |
func SetConsumeAutoAck(autoAck bool) RequestFunc {
|
70 | |
return func(ctx context.Context, pub *amqp.Publishing) context.Context {
|
|
70 |
return func(ctx context.Context, pub *amqp.Publishing, _ *amqp.Delivery) context.Context {
|
71 | 71 |
return context.WithValue(ctx, ContextKeyAutoAck, autoAck)
|
72 | 72 |
}
|
73 | 73 |
}
|
|
76 | 76 |
// function.
|
77 | 77 |
// It is designed to be used by Publishers.
|
78 | 78 |
func SetConsumeArgs(args amqp.Table) RequestFunc {
|
79 | |
return func(ctx context.Context, pub *amqp.Publishing) context.Context {
|
|
79 |
return func(ctx context.Context, pub *amqp.Publishing, _ *amqp.Delivery) context.Context {
|
80 | 80 |
return context.WithValue(ctx, ContextKeyConsumeArgs, args)
|
81 | 81 |
}
|
82 | 82 |
}
|
|
84 | 84 |
// SetContentType returns a RequestFunc that sets the ContentType field of
|
85 | 85 |
// an AMQP Publishing.
|
86 | 86 |
func SetContentType(contentType string) RequestFunc {
|
87 | |
return func(ctx context.Context, pub *amqp.Publishing) context.Context {
|
|
87 |
return func(ctx context.Context, pub *amqp.Publishing, _ *amqp.Delivery) context.Context {
|
88 | 88 |
pub.ContentType = contentType
|
89 | 89 |
return ctx
|
90 | 90 |
}
|
|
93 | 93 |
// SetContentEncoding returns a RequestFunc that sets the ContentEncoding field
|
94 | 94 |
// of an AMQP Publishing.
|
95 | 95 |
func SetContentEncoding(contentEncoding string) RequestFunc {
|
96 | |
return func(ctx context.Context, pub *amqp.Publishing) context.Context {
|
|
96 |
return func(ctx context.Context, pub *amqp.Publishing, _ *amqp.Delivery) context.Context {
|
97 | 97 |
pub.ContentEncoding = contentEncoding
|
98 | 98 |
return ctx
|
99 | 99 |
}
|
|
102 | 102 |
// SetCorrelationID returns a RequestFunc that sets the CorrelationId field
|
103 | 103 |
// of an AMQP Publishing.
|
104 | 104 |
func SetCorrelationID(cid string) RequestFunc {
|
105 | |
return func(ctx context.Context, pub *amqp.Publishing) context.Context {
|
|
105 |
return func(ctx context.Context, pub *amqp.Publishing, _ *amqp.Delivery) context.Context {
|
106 | 106 |
pub.CorrelationId = cid
|
107 | 107 |
return ctx
|
108 | 108 |
}
|