Repository navigation
Issue #1237: support builder for topicsConsumer - #1269
Conversation
| if (topicName != null) { | ||
| return client.subscribeAsync(topicName, subscriptionName, conf); | ||
| } else { | ||
| return client.subscribeAsync(topicNames, subscriptionName, conf); |
There was a problem hiding this comment.
@zhaijack I think we should remove the subscribeAsync(List<String> topics) method because all the subscribe() methods are deprecated in 2.0
There was a problem hiding this comment.
Oh, Thanks, I see.
| @@ -85,6 +86,15 @@ public interface ConsumerBuilder extends Serializable, Cloneable { | |||
| */ | |||
| ConsumerBuilder topic(String topicName); | |||
There was a problem hiding this comment.
Can we just change this to topic(String... topicNames) without adding topics method?
in subscribeAsync(), you can decide whether to subscribe to one topic or multiple topics.
internally in the builder you can maintain a Set<String> topics. so this allows you write in a more fluent style.
- subscribe to a topic:
builder.topic("topic-1") - subscribe to multiple topics:
builder.topic("topic-1", "topic-2", "topic-3") - subscribe to multiple topics in a chain way:
builder.topic("topic-1").topic("topic-2").topic("topic-3")
in subscribeAsync: you can check if (topics.size == 1) to design what to do.
does this sound better? @merlimat
There was a problem hiding this comment.
It is good. @merlimat, Do you prefer this one?
If yes, will do the change.
7ec05db to
77d5e3a
Compare
1574533 to
10aefc0
Compare
| .topics(topicNames) | ||
| .subscriptionName(subscriptionName) | ||
| .subscriptionType(SubscriptionType.Shared) | ||
| .ackTimeout(ackTimeOutMillis, TimeUnit.MILLISECONDS) |
There was a problem hiding this comment.
you need configure receiverQueueSize(4) no? there was setReceiverQueueSize(4) at ConsumerConfiguration?
| .topic(topicName3) | ||
| .subscriptionName(subscriptionName) | ||
| .subscriptionType(SubscriptionType.Shared) | ||
| .ackTimeout(ackTimeOutMillis, TimeUnit.MILLISECONDS) |
There was a problem hiding this comment.
you need configure receiverQueueSize(4) no? there was setReceiverQueueSize(4) at ConsumerConfiguration?
| .topics(topicNames) | ||
| .subscriptionName(subscriptionName) | ||
| .subscriptionType(SubscriptionType.Shared) | ||
| .ackTimeout(ackTimeOutMillis, TimeUnit.MILLISECONDS) |
| Consumer consumer = pulsarClient.newConsumer() | ||
| .topics(topicNames) | ||
| .subscriptionName(subscriptionName) | ||
| .subscriptionType(SubscriptionType.Shared) |
| .topics(topicNames) | ||
| .subscriptionName(subscriptionName) | ||
| .subscriptionType(SubscriptionType.Shared) | ||
| .ackTimeout(ackTimeOutMillis, TimeUnit.MILLISECONDS) |
| private String topicName; | ||
| private String subscriptionName; | ||
| private final ConsumerConfiguration conf; | ||
| private List<String> topicNames; |
There was a problem hiding this comment.
I would suggest using Set instead of List, so this allows us removing duplicated topic names.
| if (this.topicNames == null) { | ||
| this.topicNames = topicNames; | ||
| } else { | ||
| topicNames.forEach(name -> { |
There was a problem hiding this comment.
this.topicNames.addAll(topicNames)
|
@sijie Thanks, have changed it. receiverQueueSize was added to test some functionality. added it back here. |
8d003fa to
a731eea
Compare
Motivation
According to PIP-12, we need to support builder for topicsConsumer
Modifications
ConsumerBuilder topics(List<String> topicNames)in ConsumerBuilderResult
user could subscribe topics with builder mode.