Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[issue #807] dlq topic producer options #809

Merged
merged 4 commits into from
Sep 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pulsar/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ type DLQPolicy struct {
// DeadLetterTopic specifies the name of the topic where the failing messages will be sent.
DeadLetterTopic string

// ProducerOptions is the producer options to produce messages to the DLQ and RLQ topic
ProducerOptions ProducerOptions

// RetryLetterTopic specifies the name of the topic where the retry messages will be sent.
RetryLetterTopic string
}
Expand Down
28 changes: 24 additions & 4 deletions pulsar/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,19 @@ func TestConsumerReceiveErrAfterClose(t *testing.T) {
}

func TestDLQ(t *testing.T) {
DLQWithProducerOptions(t, nil)
}

func TestDLQWithProducerOptions(t *testing.T) {
DLQWithProducerOptions(t,
&ProducerOptions{
BatchingMaxPublishDelay: 100 * time.Millisecond,
BatchingMaxSize: 64 * 1024,
CompressionType: ZLib,
})
}

func DLQWithProducerOptions(t *testing.T, prodOpt *ProducerOptions) {
client, err := NewClient(ClientOptions{
URL: lookupURL,
})
Expand All @@ -1045,15 +1058,19 @@ func TestDLQ(t *testing.T) {
ctx := context.Background()

// create consumer
dlqPolicy := DLQPolicy{
MaxDeliveries: 3,
DeadLetterTopic: dlqTopic,
}
if prodOpt != nil {
dlqPolicy.ProducerOptions = *prodOpt
}
consumer, err := client.Subscribe(ConsumerOptions{
Topic: topic,
SubscriptionName: "my-sub",
NackRedeliveryDelay: 1 * time.Second,
Type: Shared,
DLQ: &DLQPolicy{
MaxDeliveries: 3,
DeadLetterTopic: dlqTopic,
},
DLQ: &dlqPolicy,
})
assert.Nil(t, err)
defer consumer.Close()
Expand Down Expand Up @@ -1156,6 +1173,9 @@ func TestDLQMultiTopics(t *testing.T) {
DLQ: &DLQPolicy{
MaxDeliveries: 3,
DeadLetterTopic: dlqTopic,
ProducerOptions: ProducerOptions{
BatchingMaxPublishDelay: 100 * time.Millisecond,
},
},
})
assert.Nil(t, err)
Expand Down
16 changes: 10 additions & 6 deletions pulsar/dlq_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,16 @@ func (r *dlqRouter) getProducer(schema Schema) Producer {
// Retry to create producer indefinitely
backoff := &internal.Backoff{}
for {
producer, err := r.client.CreateProducer(ProducerOptions{
Topic: r.policy.DeadLetterTopic,
CompressionType: LZ4,
BatchingMaxPublishDelay: 100 * time.Millisecond,
michaeljmarshall marked this conversation as resolved.
Show resolved Hide resolved
Schema: schema,
})
opt := r.policy.ProducerOptions
opt.Topic = r.policy.DeadLetterTopic
opt.Schema = schema

// the origin code sets to LZ4 compression with no options
// so the new design allows compression type to be overwritten but still set lz4 by default
if r.policy.ProducerOptions.CompressionType == NoCompression {
opt.CompressionType = LZ4
}
producer, err := r.client.CreateProducer(opt)

if err != nil {
r.log.WithError(err).Error("Failed to create DLQ producer")
Expand Down
14 changes: 9 additions & 5 deletions pulsar/retry_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,15 @@ func (r *retryRouter) getProducer() Producer {
// Retry to create producer indefinitely
backoff := &internal.Backoff{}
for {
producer, err := r.client.CreateProducer(ProducerOptions{
Topic: r.policy.RetryLetterTopic,
CompressionType: LZ4,
BatchingMaxPublishDelay: 100 * time.Millisecond,
})
opt := r.policy.ProducerOptions
opt.Topic = r.policy.RetryLetterTopic
// the origin code sets to LZ4 compression with no options
// so the new design allows compression type to be overwritten but still set lz4 by default
if r.policy.ProducerOptions.CompressionType == NoCompression {
opt.CompressionType = LZ4
}

producer, err := r.client.CreateProducer(opt)

if err != nil {
r.log.WithError(err).Error("Failed to create RLQ producer")
Expand Down