Source:
public void run() { Logging.putPrefix(RpcClientFactory.LOG_PREFIX); if (topics.isEmpty()) { waitTillFirstTopicIsAdded(); LOG.info("First topic is added, consumer will be started."); } while (!closed.get()) { try { subscribeToTopics(); ConsumerRecords<String, byte[]> records = consumer.poll(java.time.Duration.ofMillis(Long.MAX_VALUE)); for (ConsumerRecord<String, byte[]> record : records) { ResponseCallback responseCb = rpcResponseMap.get(record.key()); if (responseCb != null) { RpcMessageProtos.RpcMessage rpcMessage = RpcMessageProtos.RpcMessage .parseFrom(record.value()); ByteString rpcContent = rpcMessage.getRpcContent(); if (rpcMessage.getTotalChunks() > 1) { String rpcId = rpcMessage.getRpcId(); ByteString byteString = messageCache.get(rpcId); if (byteString != null) { messageCache.put(rpcId, byteString.concat(rpcMessage.getRpcContent())); } else { messageCache.put(rpcId, rpcMessage.getRpcContent()); } if (rpcMessage.getTotalChunks() != rpcMessage.getCurrentChunkNumber() + 1) { continue; } rpcContent = messageCache.get(rpcId); } if (LOG.isTraceEnabled()) { LOG.trace("Received RPC response for id {}", rpcMessage.getRpcId()); } final String rpcMessageContent = rpcContent.toStringUtf8(); responseHandlerExecutor.execute(() -> responseCb.sendResponse(rpcMessageContent)); } else { LOG.warn("Received a response for request with ID:{}, but no outstanding request was found with this id, The request may have timed out.", record.key()); } } } catch (InvalidProtocolBufferException e) { LOG.error("error while parsing response", e); } catch (WakeupException e) { LOG.info("consumer got wakeup exception, closed = ", closed.get(), e); } catch (Throwable e) { LOG.info("error in kafka consumer", e); } } consumer.close(); closed.set(true); }

Target:
public void run() { Logging.putPrefix(RpcClientFactory.LOG_PREFIX); if (topics.isEmpty()) { waitTillFirstTopicIsAdded(); LOG.info("First topic is added, consumer will be started."); } while (!closed.get()) { try { subscribeToTopics(); ConsumerRecords<String, byte[]> records = consumer.poll(java.time.Duration.ofMillis(Long.MAX_VALUE)); for (ConsumerRecord<String, byte[]> record : records) { ResponseCallback responseCb = rpcResponseMap.get(record.key()); if (responseCb != null) { RpcMessageProtos.RpcMessage rpcMessage = RpcMessageProtos.RpcMessage .parseFrom(record.value()); ByteString rpcContent = rpcMessage.getRpcContent(); if (rpcMessage.getTotalChunks() > 1) { String rpcId = rpcMessage.getRpcId(); ByteString byteString = messageCache.get(rpcId); if (byteString != null) { messageCache.put(rpcId, byteString.concat(rpcMessage.getRpcContent())); } else { messageCache.put(rpcId, rpcMessage.getRpcContent()); } if (rpcMessage.getTotalChunks() != rpcMessage.getCurrentChunkNumber() + 1) { continue; } rpcContent = messageCache.get(rpcId); } if (LOG.isTraceEnabled()) { LOG.trace("Received RPC response for id {}", rpcMessage.getRpcId()); } final String rpcMessageContent = rpcContent.toStringUtf8(); responseHandlerExecutor.execute(() -> responseCb.sendResponse(rpcMessageContent)); } else { LOG.warn("Received a response for request with ID:{}, but no outstanding request was found with this id, The request may have timed out.", record.key()); } } } catch (InvalidProtocolBufferException e) { LOG.error("error while parsing response", e); } catch (WakeupException e) { LOG.info("consumer got wakeup exception, closed = ", closed.get(), e); } catch (Throwable e) { LOG.error("Unexpected error in kafka consumer.", e); } } consumer.close(); }