go-micro.dev/v5@v5.12.0/broker/rabbitmq/options.go (about) 1 package rabbitmq 2 3 import ( 4 "context" 5 "time" 6 7 "go-micro.dev/v5/broker" 8 "go-micro.dev/v5/client" 9 "go-micro.dev/v5/server" 10 ) 11 12 type durableQueueKey struct{} 13 type headersKey struct{} 14 type queueArgumentsKey struct{} 15 type prefetchCountKey struct{} 16 type prefetchGlobalKey struct{} 17 type confirmPublishKey struct{} 18 type exchangeKey struct{} 19 type exchangeTypeKey struct{} 20 type withoutExchangeKey struct{} 21 type requeueOnErrorKey struct{} 22 type deliveryMode struct{} 23 type priorityKey struct{} 24 type contentType struct{} 25 type contentEncoding struct{} 26 type correlationID struct{} 27 type replyTo struct{} 28 type expiration struct{} 29 type messageID struct{} 30 type timestamp struct{} 31 type typeMsg struct{} 32 type userID struct{} 33 type appID struct{} 34 type externalAuth struct{} 35 type durableExchange struct{} 36 37 // ServerDurableQueue provide durable queue option for micro.RegisterSubscriber 38 func ServerDurableQueue() server.SubscriberOption { 39 return setServerSubscriberOption(durableQueueKey{}, true) 40 } 41 42 // ServerAckOnSuccess export AckOnSuccess server.SubscriberOption 43 func ServerAckOnSuccess() server.SubscriberOption { 44 return setServerSubscriberOption(ackSuccessKey{}, true) 45 } 46 47 // DurableQueue creates a durable queue when subscribing. 48 func DurableQueue() broker.SubscribeOption { 49 return setSubscribeOption(durableQueueKey{}, true) 50 } 51 52 // DurableExchange is an option to set the Exchange to be durable. 53 func DurableExchange() broker.Option { 54 return setBrokerOption(durableExchange{}, true) 55 } 56 57 // Headers adds headers used by the headers exchange. 58 func Headers(h map[string]interface{}) broker.SubscribeOption { 59 return setSubscribeOption(headersKey{}, h) 60 } 61 62 // QueueArguments sets arguments for queue creation. 63 func QueueArguments(h map[string]interface{}) broker.SubscribeOption { 64 return setSubscribeOption(queueArgumentsKey{}, h) 65 } 66 67 func RequeueOnError() broker.SubscribeOption { 68 return setSubscribeOption(requeueOnErrorKey{}, true) 69 } 70 71 // ExchangeName is an option to set the ExchangeName. 72 func ExchangeName(e string) broker.Option { 73 return setBrokerOption(exchangeKey{}, e) 74 } 75 76 // WithoutExchange is an option to use the rabbitmq default exchange. 77 // means it would not create any custom exchange. 78 func WithoutExchange() broker.Option { 79 return setBrokerOption(withoutExchangeKey{}, true) 80 } 81 82 // ExchangeType is an option to set the rabbitmq exchange type. 83 func ExchangeType(t MQExchangeType) broker.Option { 84 return setBrokerOption(exchangeTypeKey{}, t) 85 } 86 87 // PrefetchCount ... 88 func PrefetchCount(c int) broker.Option { 89 return setBrokerOption(prefetchCountKey{}, c) 90 } 91 92 // PrefetchGlobal creates a durable queue when subscribing. 93 func PrefetchGlobal() broker.Option { 94 return setBrokerOption(prefetchGlobalKey{}, true) 95 } 96 97 // ConfirmPublish ensures all published messages are confirmed by waiting for an ack/nack from the broker. 98 func ConfirmPublish() broker.Option { 99 return setBrokerOption(confirmPublishKey{}, true) 100 } 101 102 // DeliveryMode sets a delivery mode for publishing. 103 func DeliveryMode(value uint8) broker.PublishOption { 104 return setPublishOption(deliveryMode{}, value) 105 } 106 107 // Priority sets a priority level for publishing. 108 func Priority(value uint8) broker.PublishOption { 109 return setPublishOption(priorityKey{}, value) 110 } 111 112 // ContentType sets a property MIME content type for publishing. 113 func ContentType(value string) broker.PublishOption { 114 return setPublishOption(contentType{}, value) 115 } 116 117 // ContentEncoding sets a property MIME content encoding for publishing. 118 func ContentEncoding(value string) broker.PublishOption { 119 return setPublishOption(contentEncoding{}, value) 120 } 121 122 // CorrelationID sets a property correlation ID for publishing. 123 func CorrelationID(value string) broker.PublishOption { 124 return setPublishOption(correlationID{}, value) 125 } 126 127 // ReplyTo sets a property address to to reply to (ex: RPC) for publishing. 128 func ReplyTo(value string) broker.PublishOption { 129 return setPublishOption(replyTo{}, value) 130 } 131 132 // Expiration sets a property message expiration spec for publishing. 133 func Expiration(value string) broker.PublishOption { 134 return setPublishOption(expiration{}, value) 135 } 136 137 // MessageId sets a property message identifier for publishing. 138 func MessageId(value string) broker.PublishOption { 139 return setPublishOption(messageID{}, value) 140 } 141 142 // Timestamp sets a property message timestamp for publishing. 143 func Timestamp(value time.Time) broker.PublishOption { 144 return setPublishOption(timestamp{}, value) 145 } 146 147 // TypeMsg sets a property message type name for publishing. 148 func TypeMsg(value string) broker.PublishOption { 149 return setPublishOption(typeMsg{}, value) 150 } 151 152 // UserID sets a property user id for publishing. 153 func UserID(value string) broker.PublishOption { 154 return setPublishOption(userID{}, value) 155 } 156 157 // AppID sets a property application id for publishing. 158 func AppID(value string) broker.PublishOption { 159 return setPublishOption(appID{}, value) 160 } 161 162 func ExternalAuth() broker.Option { 163 return setBrokerOption(externalAuth{}, ExternalAuthentication{}) 164 } 165 166 type subscribeContextKey struct{} 167 168 // SubscribeContext set the context for broker.SubscribeOption. 169 func SubscribeContext(ctx context.Context) broker.SubscribeOption { 170 return setSubscribeOption(subscribeContextKey{}, ctx) 171 } 172 173 type ackSuccessKey struct{} 174 175 // AckOnSuccess will automatically acknowledge messages when no error is returned. 176 func AckOnSuccess() broker.SubscribeOption { 177 return setSubscribeOption(ackSuccessKey{}, true) 178 } 179 180 // PublishDeliveryMode client.PublishOption for setting message "delivery mode" 181 // mode , Transient (0 or 1) or Persistent (2) 182 func PublishDeliveryMode(mode uint8) client.PublishOption { 183 return func(o *client.PublishOptions) { 184 if o.Context == nil { 185 o.Context = context.Background() 186 } 187 o.Context = context.WithValue(o.Context, deliveryMode{}, mode) 188 } 189 }