Skip to content

Commit

Permalink
[IMPROVED] Add extra option to OrderedConsumerConfig (#1737)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Wain <michael@sanity.io>
  • Loading branch information
mwain authored Dec 19, 2024
1 parent 48391f1 commit 6977981
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions jetstream/consumer_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ type (
// Maximum number of attempts for the consumer to be recreated in a
// single recreation cycle. Defaults to unlimited.
MaxResetAttempts int

// Metadata is a set of application-defined key-value pairs for
// associating metadata on the consumer. This feature requires
// nats-server v2.10.0 or later.
Metadata map[string]string `json:"metadata,omitempty"`
}

// DeliverPolicy determines from which point to start delivering messages.
Expand Down
1 change: 1 addition & 0 deletions jetstream/ordered.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ func (c *orderedConsumer) getConsumerConfig() *ConsumerConfig {
Replicas: 1,
HeadersOnly: c.cfg.HeadersOnly,
MemoryStorage: true,
Metadata: c.cfg.Metadata,
}
if len(c.cfg.FilterSubjects) == 1 {
cfg.FilterSubject = c.cfg.FilterSubjects[0]
Expand Down
4 changes: 4 additions & 0 deletions jetstream/test/ordered_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2006,6 +2006,7 @@ func TestOrderedConsumerConfig(t *testing.T) {
ReplayPolicy: jetstream.ReplayOriginalPolicy,
InactiveThreshold: 10 * time.Second,
HeadersOnly: true,
Metadata: map[string]string{"foo": "a"},
},
expected: jetstream.ConsumerConfig{
FilterSubjects: []string{"foo.a", "foo.b"},
Expand All @@ -2018,6 +2019,7 @@ func TestOrderedConsumerConfig(t *testing.T) {
Replicas: 1,
MemoryStorage: true,
HeadersOnly: true,
Metadata: map[string]string{"foo": "a"},
},
},
{
Expand All @@ -2029,6 +2031,7 @@ func TestOrderedConsumerConfig(t *testing.T) {
ReplayPolicy: jetstream.ReplayOriginalPolicy,
InactiveThreshold: 10 * time.Second,
HeadersOnly: true,
Metadata: map[string]string{"foo": "a"},
},
expected: jetstream.ConsumerConfig{
FilterSubjects: []string{"foo.a", "foo.b"},
Expand All @@ -2041,6 +2044,7 @@ func TestOrderedConsumerConfig(t *testing.T) {
Replicas: 1,
MemoryStorage: true,
HeadersOnly: true,
Metadata: map[string]string{"foo": "a"},
},
},
{
Expand Down

0 comments on commit 6977981

Please sign in to comment.