From 6035642336b149c070c7ab2b1861668267529ca3 Mon Sep 17 00:00:00 2001 From: Wondertan Date: Sun, 9 Jan 2022 18:23:33 +0200 Subject: [PATCH] feat: new WithMsgIdFunction topic option to enable topics to have own msg id generation rules --- pubsub.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pubsub.go b/pubsub.go index 7caf5ada..e817be44 100644 --- a/pubsub.go +++ b/pubsub.go @@ -1160,6 +1160,14 @@ type TopicOptions struct{} type TopicOpt func(t *Topic) error +// WithMsgIdFunction sets custom MsgIdFunction for a Topic, enabling topics to have own msg id generation rules. +func (p *PubSub) WithMsgIdFunction(msgId MsgIdFunction) TopicOpt { + return func(t *Topic) error { + t.p.idGen.Set(t.topic, msgId) + return nil + } +} + // Join joins the topic and returns a Topic handle. Only one Topic handle should exist per topic, and Join will error if // the Topic handle already exists. func (p *PubSub) Join(topic string, opts ...TopicOpt) (*Topic, error) {