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

[fix][client] Fix DLQ producer name conflicts when multiples consumers send messages to DLQ #21890

Merged
merged 1 commit into from
Jan 15, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ public void testDeadLetterTopicWithMessageKey() throws Exception {
public void testDeadLetterTopicWithProducerName() throws Exception {
final String topic = "persistent://my-property/my-ns/dead-letter-topic";
final String subscription = "my-subscription";
String deadLetterProducerName = String.format("%s-%s-DLQ", topic, subscription);
final String consumerName = "my-consumer";
String deadLetterProducerName = String.format("%s-%s-%s-DLQ", topic, subscription, consumerName);

final int maxRedeliveryCount = 1;

Expand All @@ -149,6 +150,7 @@ public void testDeadLetterTopicWithProducerName() throws Exception {
Consumer<byte[]> consumer = pulsarClient.newConsumer(Schema.BYTES)
.topic(topic)
.subscriptionName(subscription)
.consumerName(consumerName)
.subscriptionType(SubscriptionType.Shared)
.ackTimeout(1, TimeUnit.SECONDS)
.deadLetterPolicy(DeadLetterPolicy.builder().maxRedeliverCount(maxRedeliveryCount).build())
Expand Down Expand Up @@ -929,6 +931,9 @@ public void testDeadLetterTopicWithInitialSubscriptionAndMultiConsumers() throws
assertTrue(admin.topics().getSubscriptions(deadLetterTopic).contains(dlqInitialSub));
});

// We should assert that all consumers are able to produce messages to DLQ
assertEquals(admin.topics().getStats(deadLetterTopic).getPublishers().size(), 2);

Consumer<byte[]> deadLetterConsumer = newPulsarClient.newConsumer(Schema.BYTES)
.topic(deadLetterTopic)
.subscriptionName(dlqInitialSub)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2172,7 +2172,8 @@ private void initDeadLetterProducerIfNeeded() {
((ProducerBuilderImpl<byte[]>) client.newProducer(Schema.AUTO_PRODUCE_BYTES(schema)))
.initialSubscriptionName(this.deadLetterPolicy.getInitialSubscriptionName())
.topic(this.deadLetterPolicy.getDeadLetterTopic())
.producerName(String.format("%s-%s-DLQ", this.topicName, this.subscription))
.producerName(String.format("%s-%s-%s-DLQ", this.topicName, this.subscription,
this.consumerName))
.blockIfQueueFull(false)
.enableBatching(false)
.enableChunking(true)
Expand Down
Loading