sijie closed pull request #2506: TopicPatterns are now supported by python
functions
URL: https://github.com/apache/incubator-pulsar/pull/2506
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/pulsar-functions/instance/src/main/python/python_instance.py
b/pulsar-functions/instance/src/main/python/python_instance.py
index ce99020fd5..c72a7e0a0f 100644
--- a/pulsar-functions/instance/src/main/python/python_instance.py
+++ b/pulsar-functions/instance/src/main/python/python_instance.py
@@ -172,7 +172,7 @@ def run(self):
self.consumers[topic] = self.pulsar_client.subscribe(
str(topic), subscription_name,
consumer_type=mode,
- message_listener=partial(self.message_listener, topic,
self.input_serdes[topic]),
+ message_listener=partial(self.message_listener,
self.input_serdes[topic]),
unacked_messages_timeout_ms=int(self.timeout_ms) if self.timeout_ms
else None
)
@@ -183,12 +183,20 @@ def run(self):
serde_kclass = util.import_class(os.path.dirname(self.user_code),
consumer_conf.serdeClassName)
self.input_serdes[topic] = serde_kclass()
Log.info("Setting up consumer for topic %s with subname %s" % (topic,
subscription_name))
- self.consumers[topic] = self.pulsar_client.subscribe(
- str(topic), subscription_name,
- consumer_type=mode,
- message_listener=partial(self.message_listener, topic,
self.input_serdes[topic]),
- unacked_messages_timeout_ms=int(self.timeout_ms) if self.timeout_ms
else None
- )
+ if consumer_conf.isRegexPattern:
+ self.consumers[topic] = self.pulsar_client.subscribe_pattern(
+ str(topic), subscription_name,
+ consumer_type=mode,
+ message_listener=partial(self.message_listener,
self.input_serdes[topic]),
+ unacked_messages_timeout_ms=int(self.timeout_ms) if self.timeout_ms
else None
+ )
+ else:
+ self.consumers[topic] = self.pulsar_client.subscribe(
+ str(topic), subscription_name,
+ consumer_type=mode,
+ message_listener=partial(self.message_listener,
self.input_serdes[topic]),
+ unacked_messages_timeout_ms=int(self.timeout_ms) if self.timeout_ms
else None
+ )
function_kclass = util.import_class(os.path.dirname(self.user_code),
self.instance_config.function_details.className)
if function_kclass is None:
@@ -301,8 +309,8 @@ def setup_producer(self):
batching_max_publish_delay_ms=1,
max_pending_messages=100000)
- def message_listener(self, topic, serde, consumer, message):
- item = InternalMessage(message, topic, serde, consumer)
+ def message_listener(self, serde, consumer, message):
+ item = InternalMessage(message, consumer.topic(), serde, consumer)
self.queue.put(item, True)
if self.atmost_once and self.auto_ack:
consumer.acknowledge(message)
diff --git a/pulsar-functions/instance/src/main/python/python_instance_main.py
b/pulsar-functions/instance/src/main/python/python_instance_main.py
index 514d7fe9f3..d9f1132bfb 100644
--- a/pulsar-functions/instance/src/main/python/python_instance_main.py
+++ b/pulsar-functions/instance/src/main/python/python_instance_main.py
@@ -82,9 +82,6 @@ def main():
Log.info("Starting Python instance with %s" % str(args))
- if function_details.source.topicsPattern:
- raise ValueError('topicsPattern is not supported by python client')
-
authentication = None
use_tls = False
tls_allow_insecure_connection = False
diff --git
a/pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/validation/ValidatorImpls.java
b/pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/validation/ValidatorImpls.java
index cbeb970f77..f264d2aa57 100644
---
a/pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/validation/ValidatorImpls.java
+++
b/pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/validation/ValidatorImpls.java
@@ -506,15 +506,6 @@ private static void doPythonChecks(FunctionConfig
functionConfig, String name) {
if (functionConfig.getWindowConfig() != null) {
throw new IllegalArgumentException("There is currently no
support windowing in python");
}
-
- if (functionConfig.getTopicsPattern() != null &&
!functionConfig.getTopicsPattern().isEmpty()) {
- throw new IllegalArgumentException("Topic-patterns is not
supported for python runtime");
- }
- functionConfig.getInputSpecs().forEach((topic, conf) -> {
- if (conf.isRegexPattern()) {
- throw new IllegalArgumentException("Topic-patterns is not
supported for python runtime");
- }
- });
}
private static void verifyNoTopicClash(Collection<String> inputTopics,
String outputTopic) throws IllegalArgumentException {
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services