forked from apache/pulsar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature][client] PIP-184: Topic specific consumer priorityLevel
Resolves apache#16481
- Loading branch information
Dave Maughan
committed
Jul 26, 2022
1 parent
6f1f6aa
commit cb82d6c
Showing
13 changed files
with
446 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
pulsar-client-api/src/main/java/org/apache/pulsar/client/api/TopicConsumerBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pulsar.client.api; | ||
|
||
/** | ||
* {@link TopicConsumerBuilder} is used to configure topic specific options to override those set at the | ||
* {@link ConsumerBuilder} level. | ||
* | ||
* @see ConsumerBuilder#topicConfiguration(String) | ||
* | ||
* @param <T> the type of the value in the {@link ConsumerBuilder} | ||
*/ | ||
public interface TopicConsumerBuilder<T> { | ||
/** | ||
* Configure the priority level of this topic. | ||
* | ||
* @see ConsumerBuilder#priorityLevel(int) | ||
* | ||
* @param priorityLevel the priority of this topic | ||
* @return the {@link TopicConsumerBuilder} instance | ||
*/ | ||
TopicConsumerBuilder<T> priorityLevel(int priorityLevel); | ||
|
||
/** | ||
* Complete the configuration of the topic specific options and return control back to the | ||
* {@link ConsumerBuilder} instance. | ||
* | ||
* @return the {@link ConsumerBuilder} instance | ||
*/ | ||
ConsumerBuilder<T> build(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
pulsar-client/src/main/java/org/apache/pulsar/client/impl/TopicConsumerBuilderImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pulsar.client.impl; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
import lombok.RequiredArgsConstructor; | ||
import org.apache.pulsar.client.api.ConsumerBuilder; | ||
import org.apache.pulsar.client.api.TopicConsumerBuilder; | ||
import org.apache.pulsar.client.impl.conf.TopicConsumerConfigurationData; | ||
|
||
@RequiredArgsConstructor | ||
class TopicConsumerBuilderImpl<T> implements TopicConsumerBuilder<T> { | ||
private final ConsumerBuilder<T> consumerBuilder; | ||
private final TopicConsumerConfigurationData topicConf; | ||
|
||
@Override | ||
public TopicConsumerBuilder<T> priorityLevel(int priorityLevel) { | ||
checkArgument(priorityLevel >= 0, "priorityLevel needs to be >= 0"); | ||
topicConf.setPriorityLevel(priorityLevel); | ||
return this; | ||
} | ||
|
||
@Override | ||
public ConsumerBuilder<T> build() { | ||
return consumerBuilder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...ient/src/main/java/org/apache/pulsar/client/impl/conf/TopicConsumerConfigurationData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pulsar.client.impl.conf; | ||
|
||
import java.io.Serializable; | ||
import java.util.regex.Pattern; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.NonNull; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class TopicConsumerConfigurationData implements Serializable { | ||
private static final long serialVersionUID = 1L; | ||
|
||
@NonNull | ||
private Pattern topicsPattern; | ||
private int priorityLevel; | ||
|
||
public boolean matchesTopicName(String topicName) { | ||
if (topicsPattern == null || topicName == null) { | ||
return false; | ||
} | ||
return topicsPattern.matcher(topicName).matches(); | ||
} | ||
|
||
public static TopicConsumerConfigurationData of(@NonNull String topicNameOrPattern, | ||
ConsumerConfigurationData<?> conf) { | ||
return of(topicNameOrPattern, conf.getPriorityLevel()); | ||
} | ||
|
||
public static TopicConsumerConfigurationData of(@NonNull String topicNameOrPattern, int priorityLevel) { | ||
Pattern topicsPattern = Pattern.compile(topicNameOrPattern); | ||
return new TopicConsumerConfigurationData(topicsPattern, priorityLevel); | ||
} | ||
|
||
public static void main(String[] args) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.