srkukarni commented on a change in pull request #7180: URL: https://github.com/apache/pulsar/pull/7180#discussion_r435741992
########## File path: pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/FunctionAssignmentTailer.java ########## @@ -18,56 +18,90 @@ */ package org.apache.pulsar.functions.worker; -import java.io.IOException; -import java.util.function.Function; - +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; import org.apache.pulsar.client.api.Message; -import org.apache.pulsar.client.api.PulsarClientException.AlreadyClosedException; +import org.apache.pulsar.client.api.MessageId; +import org.apache.pulsar.client.api.PulsarClientException; import org.apache.pulsar.client.api.Reader; -import org.apache.pulsar.common.util.FutureUtil; +import org.apache.pulsar.client.api.ReaderBuilder; import org.apache.pulsar.functions.proto.Function.Assignment; -import lombok.extern.slf4j.Slf4j; +import java.io.IOException; @Slf4j -public class FunctionAssignmentTailer - implements java.util.function.Consumer<Message<byte[]>>, Function<Throwable, Void>, AutoCloseable { +public class FunctionAssignmentTailer implements AutoCloseable { private final FunctionRuntimeManager functionRuntimeManager; + @Getter private final Reader<byte[]> reader; - private boolean closed = false; + private volatile boolean isRunning = false; - public FunctionAssignmentTailer(FunctionRuntimeManager functionRuntimeManager, Reader<byte[]> reader) { + private final Thread tailerThread; + + public FunctionAssignmentTailer(FunctionRuntimeManager functionRuntimeManager, ReaderBuilder readerBuilder, WorkerConfig workerConfig) throws PulsarClientException { this.functionRuntimeManager = functionRuntimeManager; - this.reader = reader; - } + + this.reader = readerBuilder + .subscriptionRolePrefix(workerConfig.getWorkerId() + "-function-runtime-manager") + .readerName(workerConfig.getWorkerId() + "-function-runtime-manager") + .topic(workerConfig.getFunctionAssignmentTopic()) + .readCompacted(true) + .startMessageId(MessageId.earliest) + .create(); - public void start() { - receiveOne(); + this.tailerThread = new Thread(() -> { + while(true) { Review comment: instead of two while loop, maybe you can do while(isRunning) { try { readNext(); processAssignment(); } catch (Exeepton e) { see what kind of exception ---------------------------------------------------------------- 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: us...@infra.apache.org