From 09bc84c5c95a643a3f4a27402e73c4dd1fc00649 Mon Sep 17 00:00:00 2001 From: quexer Date: Sun, 22 Oct 2023 10:52:21 +0800 Subject: [PATCH] feat: add client.PublishOption for setting message delivery mode --- v4/broker/rabbitmq/options.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/v4/broker/rabbitmq/options.go b/v4/broker/rabbitmq/options.go index 4a31846e..790076b8 100644 --- a/v4/broker/rabbitmq/options.go +++ b/v4/broker/rabbitmq/options.go @@ -5,6 +5,7 @@ import ( "time" "go-micro.dev/v4/broker" + "go-micro.dev/v4/client" ) type durableQueueKey struct{} @@ -164,3 +165,14 @@ type ackSuccessKey struct{} func AckOnSuccess() broker.SubscribeOption { return setSubscribeOption(ackSuccessKey{}, true) } + +// PublishDeliveryMode client.PublishOption for setting message "delivery mode" +// mode , Transient (0 or 1) or Persistent (2) +func PublishDeliveryMode(mode uint8) client.PublishOption { + return func(o *client.PublishOptions) { + if o.Context == nil { + o.Context = context.Background() + } + o.Context = context.WithValue(o.Context, deliveryMode{}, mode) + } +}