You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2020/04/07 17:16:35 UTC

[GitHub] [pulsar] merlimat commented on a change in pull request #6684: Support function with format: Function>

merlimat commented on a change in pull request #6684: Support function with format: Function<I, CompletableFuture<O>>
URL: https://github.com/apache/pulsar/pull/6684#discussion_r404978597
 
 

 ##########
 File path: pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/JavaInstance.java
 ##########
 @@ -52,23 +53,49 @@ public JavaInstance(ContextImpl contextImpl, Object userClassObject) {
         }
     }
 
-    public JavaExecutionResult handleMessage(Record<?> record, Object input) {
+    public CompletableFuture<JavaExecutionResult> handleMessage(Record<?> record, Object input) {
         if (context != null) {
             context.setCurrentMessageContext(record);
         }
+
+        final CompletableFuture<JavaExecutionResult> future = new CompletableFuture<>();
         JavaExecutionResult executionResult = new JavaExecutionResult();
+
         try {
             Object output;
             if (function != null) {
                 output = function.process(input, context);
             } else {
                 output = javaUtilFunction.apply(input);
             }
-            executionResult.setResult(output);
+
+            if (output instanceof CompletableFuture) {
+                // Function is in format: Function<I, CompletableFuture<O>>
+                ((CompletableFuture) output).whenComplete((obj, throwable) -> {
 
 Review comment:
   This is not applying any backpressure on the consumer. If the function doesn't have a mechanism to self-throttle, it will just blow up the memory.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services