diff --git a/consumers.go b/consumers.go index bb3c621d..485e328d 100644 --- a/consumers.go +++ b/consumers.go @@ -360,7 +360,8 @@ 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 @@ -368,6 +369,15 @@ func DeliverHeadersOnly() ConsumerOption { } } +// 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 diff --git a/test/consumers_test.go b/test/consumers_test.go index 424c7ce8..3ccf773f 100644 --- a/test/consumers_test.go +++ b/test/consumers_test.go @@ -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) {