Skip to content

Commit

Permalink
Merge pull request #546 from ramonberrutti/consumer-headers-only
Browse files Browse the repository at this point in the history
[ADD] DeliverBodies to disable headersOnly
  • Loading branch information
ripienaar authored Jul 5, 2024
2 parents 365bb50 + bd1d572 commit 2b7a6dc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 11 additions & 1 deletion consumers.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,24 @@ func StartAtTimeDelta(d time.Duration) ConsumerOption {
}
}

// DeliverHeadersOnly configures the consumer to only deliver existing header and the `Nats-Msg-Size` header, no bodies
// DeliverHeadersOnly configures the consumer to only deliver existing header and the `Nats-Msg-Size` header, no bodies.
// To deliver also the bodies use DeliverBodies.
func DeliverHeadersOnly() ConsumerOption {
return func(o *api.ConsumerConfig) error {
o.HeadersOnly = true
return nil
}
}

// DeliverBodies configures the consumer to deliver the headers and the bodies for each message.
// To only deliver headers only use DeliverHeadersOnly.
func DeliverBodies() ConsumerOption {
return func(o *api.ConsumerConfig) error {
o.HeadersOnly = false
return nil
}
}

func resetDeliverPolicy(o *api.ConsumerConfig) {
o.DeliverPolicy = api.DeliverAll
o.OptStartSeq = 0
Expand Down
6 changes: 5 additions & 1 deletion test/consumers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -915,12 +915,16 @@ func TestMaxWaiting(t *testing.T) {
}
}

func TestDeliverHeadersOnly(t *testing.T) {
func TestDeliverHeadersOnlyAndDeliverBodies(t *testing.T) {
cfg := testConsumerConfig()
jsm.DeliverHeadersOnly()(cfg)
if !cfg.HeadersOnly {
t.Fatalf("expected headers only to be set")
}
jsm.DeliverBodies()(cfg)
if cfg.HeadersOnly {
t.Fatalf("expected headers only to be false")
}
}

func TestMaxRequestBatch(t *testing.T) {
Expand Down

0 comments on commit 2b7a6dc

Please sign in to comment.