private synchronized ConsumerPool getConsumerPool(final ProcessContext context) { ConsumerPool pool = consumerPool; if (pool != null) { return pool; } return consumerPool = createConsumerPool(context, getLogger()); }
@OnUnscheduled public void interruptActiveThreads() { // There are known issues with the Kafka client library that result in the client code hanging // indefinitely when unable to communicate with the broker. In order to address this, we will wait // up to 30 seconds for the Threads to finish and then will call Consumer.wakeup() to trigger the // thread to wakeup when it is blocked, waiting on a response. final long nanosToWait = TimeUnit.SECONDS.toNanos(5L); final long start = System.nanoTime(); while (System.nanoTime() - start < nanosToWait && !activeLeases.isEmpty()) { try { Thread.sleep(100L); } catch (final InterruptedException ie) { Thread.currentThread().interrupt(); return; } } if (!activeLeases.isEmpty()) { int count = 0; for (final ConsumerLease lease : activeLeases) { getLogger().info("Consumer {} has not finished after waiting 30 seconds; will attempt to wake-up the lease", new Object[] {lease}); lease.wakeup(); count++; } getLogger().info("Woke up {} consumers", new Object[] {count}); } activeLeases.clear(); }
getLogger().warn("Was interrupted while trying to communicate with Kafka with lease {}. " + "Will roll back session and discard any partially received data.", new Object[] {lease}); } catch (final KafkaException kex) { getLogger().error("Exception while interacting with Kafka so will close the lease {} due to {}", new Object[]{lease, kex}, kex); } catch (final Throwable t) { getLogger().error("Exception while processing data from kafka so will close the lease {} due to {}", new Object[]{lease, t}, t); } finally {
return new ConsumerPool(maxLeases, readerFactory, writerFactory, props, topicPattern, maxUncommittedTime, securityProtocol, bootstrapServers, log); } else { getLogger().error("Subscription type has an unknown value {}", new Object[] {topicType}); return null;
private synchronized ConsumerPool getConsumerPool(final ProcessContext context) { ConsumerPool pool = consumerPool; if (pool != null) { return pool; } return consumerPool = createConsumerPool(context, getLogger()); }
@OnUnscheduled public void interruptActiveThreads() { // There are known issues with the Kafka client library that result in the client code hanging // indefinitely when unable to communicate with the broker. In order to address this, we will wait // up to 30 seconds for the Threads to finish and then will call Consumer.wakeup() to trigger the // thread to wakeup when it is blocked, waiting on a response. final long nanosToWait = TimeUnit.SECONDS.toNanos(5L); final long start = System.nanoTime(); while (System.nanoTime() - start < nanosToWait && !activeLeases.isEmpty()) { try { Thread.sleep(100L); } catch (final InterruptedException ie) { Thread.currentThread().interrupt(); return; } } if (!activeLeases.isEmpty()) { int count = 0; for (final ConsumerLease lease : activeLeases) { getLogger().info("Consumer {} has not finished after waiting 30 seconds; will attempt to wake-up the lease", new Object[] {lease}); lease.wakeup(); count++; } getLogger().info("Woke up {} consumers", new Object[] {count}); } activeLeases.clear(); }
getLogger().warn("Was interrupted while trying to communicate with Kafka with lease {}. " + "Will roll back session and discard any partially received data.", new Object[] {lease}); } catch (final KafkaException kex) { getLogger().error("Exception while interacting with Kafka so will close the lease {} due to {}", new Object[]{lease, kex}, kex); } catch (final Throwable t) { getLogger().error("Exception while processing data from kafka so will close the lease {} due to {}", new Object[]{lease, t}, t); } finally {
return new ConsumerPool(maxLeases, readerFactory, writerFactory, props, topicPattern, maxUncommittedTime, securityProtocol, bootstrapServers, log); } else { getLogger().error("Subscription type has an unknown value {}", new Object[] {topicType}); return null;