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:
[email protected]


With regards,
Apache Git Services

Reply via email to