Skip to content

Issue #1237: support builder for topicsConsumer - #1269

Merged
merlimat merged 4 commits into
apache:masterfrom
hellostreaming:issue_1237
Feb 22, 2018
Merged

merlimat merged 4 commits into
apache:masterfrom
hellostreaming:issue_1237

Conversation

@hellostreaming

Copy link
Copy Markdown
Contributor

Motivation

According to PIP-12, we need to support builder for topicsConsumer

Modifications

  • add ConsumerBuilder topics(List<String> topicNames) in ConsumerBuilder
  • add test for the builder

Result

user could subscribe topics with builder mode.

if (topicName != null) {
return client.subscribeAsync(topicName, subscriptionName, conf);
} else {
return client.subscribeAsync(topicNames, subscriptionName, conf);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhaijack I think we should remove the subscribeAsync(List<String> topics) method because all the subscribe() methods are deprecated in 2.0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, Thanks, I see.

@@ -85,6 +86,15 @@ public interface ConsumerBuilder extends Serializable, Cloneable {
*/
ConsumerBuilder topic(String topicName);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is good. @merlimat, Do you prefer this one?
If yes, will do the change.

.topics(topicNames)
.subscriptionName(subscriptionName)
.subscriptionType(SubscriptionType.Shared)
.ackTimeout(ackTimeOutMillis, TimeUnit.MILLISECONDS)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need configure receiverQueueSize(4) no? there was setReceiverQueueSize(4) at ConsumerConfiguration?

.topic(topicName3)
.subscriptionName(subscriptionName)
.subscriptionType(SubscriptionType.Shared)
.ackTimeout(ackTimeOutMillis, TimeUnit.MILLISECONDS)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need configure receiverQueueSize(4) no? there was setReceiverQueueSize(4) at ConsumerConfiguration?

.topics(topicNames)
.subscriptionName(subscriptionName)
.subscriptionType(SubscriptionType.Shared)
.ackTimeout(ackTimeOutMillis, TimeUnit.MILLISECONDS)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

receiverQueueSize(4)?

Consumer consumer = pulsarClient.newConsumer()
.topics(topicNames)
.subscriptionName(subscriptionName)
.subscriptionType(SubscriptionType.Shared)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

receiverQueueSize(4)

.topics(topicNames)
.subscriptionName(subscriptionName)
.subscriptionType(SubscriptionType.Shared)
.ackTimeout(ackTimeOutMillis, TimeUnit.MILLISECONDS)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

receiverQueueSize(4)?

private String topicName;
private String subscriptionName;
private final ConsumerConfiguration conf;
private List<String> topicNames;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 -> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.topicNames.addAll(topicNames)

@hellostreaming

Copy link
Copy Markdown
Contributor Author

@sijie Thanks, have changed it. receiverQueueSize was added to test some functionality. added it back here.

@merlimat merlimat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@merlimat
merlimat merged commit 68cd115 into apache:master Feb 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants