本文整理匯總了Java中org.apache.kafka.common.errors.WakeupException類的典型用法代碼示例。如果您正苦於以下問題:Java WakeupException類的具體用法?Java WakeupException怎麽用?Java WakeupException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
WakeupException類屬於org.apache.kafka.common.errors包,在下文中一共展示了WakeupException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: run
import org.apache.kafka.common.errors.WakeupException; //導入依賴的package包/類
@Override
public void run() {
try {
consumer.subscribe(Collections.singletonList(Config.getProperty("input_topic")));
while (!closed.get()) {
ConsumerRecords<String, String> records = consumer.poll(3000);
try {
consumer.commitSync(); // commit
} catch (Exception ignored) {
}
if (records.count() > 0) {
handler.consume(records);
}
}
} catch (WakeupException e) {
if (!closed.get()) throw e;
} finally {
consumer.close();
}
}
示例2: run
import org.apache.kafka.common.errors.WakeupException; //導入依賴的package包/類
public void run() {
try {
consumer.subscribe(this.topics);
while (true) {
ConsumerRecords<String, String> records = consumer.poll(Long.MAX_VALUE);
for (ConsumerRecord<String, String> record : records) {
Map<String, Object> data = new HashMap<>();
data.put("partition", record.partition());
data.put("offset", record.offset());
data.put("value", record.value());
System.out.println(data);
}
}
} catch (WakeupException e) {
// ignore for shutdown
} finally {
consumer.close();
}
}
示例3: run
import org.apache.kafka.common.errors.WakeupException; //導入依賴的package包/類
@Override
public void run() {
try {
consumer.subscribe(topics);
while (true) {
ConsumerRecords<String, String> records = consumer.poll(Long.MAX_VALUE);
for (ConsumerRecord<String, String> record : records) {
Map<String, Object> data = new HashMap<>();
data.put("partition", record.partition());
data.put("offset", record.offset());
data.put("value", record.value());
System.out.println(this.id + ": " + data);
}
}
} catch (WakeupException e) {
System.out.println("Shutting down");
} finally {
consumer.close();
}
}
示例4: run
import org.apache.kafka.common.errors.WakeupException; //導入依賴的package包/類
public void run() {
try {
printJson(new StartupComplete());
consumer.subscribe(Collections.singletonList(topic), this);
while (true) {
ConsumerRecords<String, String> records = consumer.poll(Long.MAX_VALUE);
Map<TopicPartition, OffsetAndMetadata> offsets = onRecordsReceived(records);
if (!useAutoCommit) {
if (useAsyncCommit)
consumer.commitAsync(offsets, this);
else
commitSync(offsets);
}
}
} catch (WakeupException e) {
// ignore, we are closing
} finally {
consumer.close();
printJson(new ShutdownComplete());
shutdownLatch.countDown();
}
}
示例5: run
import org.apache.kafka.common.errors.WakeupException; //導入依賴的package包/類
@Override
public void run() {
try {
consumer.subscribe(topics);
while (true) {
ConsumerRecords<String, String> records = consumer.poll(Long.MAX_VALUE);
for (ConsumerRecord<String, String> record : records) {
msgSnder.sendMessages(record.value());//record.partition();record.offset();
}
}
} catch (WakeupException e) {
// ignore for shutdown
} finally {
consumer.close();
msgSnder.close();
}
}
示例6: loop
import org.apache.kafka.common.errors.WakeupException; //導入依賴的package包/類
private void loop() {
while (!shutdown) {
try {
ConsumerRecords<String, V> records = consumer.poll(Long.MAX_VALUE);
for (ConsumerRecord<String, V> record : records) {
KafkaAsyncResponseImpl suspendedResp = suspended.get(record.key());
if (suspendedResp != null)
suspendedResp.onResponseReceived(record.value());
}
// We do not commit offset intentionally,
// as kafka consumer will reset offset to latest by default
// when startup
} catch (WakeupException wakeUp) {
//do nothing, begin next loop or shutdown
}
}
}
示例7: initiateShutdown
import org.apache.kafka.common.errors.WakeupException; //導入依賴的package包/類
public boolean initiateShutdown() {
if (running.compareAndSet(true, false)) {
LOG.info("'{}' start to shutdown... topics={}. time={}.",
this.getName(), topics.toString(), System.currentTimeMillis());
try {
// wakeup
consumer.wakeup();
} catch (WakeupException e) {
LOG.info(e.toString());
}
// try { // 打斷可能存在的在waiting狀態的推送任務
// super.interrupt();
// } catch (Exception e) {
// // ignore
// }
return true;
} else {
return false;
}
}
示例8: run
import org.apache.kafka.common.errors.WakeupException; //導入依賴的package包/類
/**
* Runnable interface implement.<BR/>
*/
@Override
public void run() {
log.debug("The handler:{} thread started.", id);
try {
subscribe(getTopicList());
while (!closed.get()) {
ConsumerRecords<String, String> records = getMessage();
log.debug("records count: {}", records.count());
if(records == null || records.isEmpty())
continue;
handle(records);
}
} catch (WakeupException e) {
log.error(e.getMessage());
//Ignore exception if closing
if(!closed.get())
throw e;
} finally {
this.close();
}
log.debug("The handler:{} thread ended.", id);
}
示例9: process
import org.apache.kafka.common.errors.WakeupException; //導入依賴的package包/類
/**
* consumer handle process
*/
public void process() {
try {
subscribe(getTopicList());
while (!closed.get()) {
ConsumerRecords<K, V> records = getMessage();
log.debug("records count: {}", records.count());
if (records == null || records.isEmpty())
continue;
handle(records);
}
} catch (WakeupException e) {
log.error(e.getMessage());
//Ignore exception if closing
if (!closed.get())
throw e;
} finally {
this.close();
}
}
示例10: pollRecords
import org.apache.kafka.common.errors.WakeupException; //導入依賴的package包/類
private void pollRecords(Handler<ConsumerRecords<K, V>> handler) {
this.worker.submit(() -> {
if (!this.closed.get()) {
try {
ConsumerRecords<K, V> records = this.consumer.poll(pollTimeout);
if (records != null && records.count() > 0) {
this.context.runOnContext(v -> handler.handle(records));
} else {
// Don't call pollRecords directly, but use schedule() to actually pause when the readStream is paused
schedule(0);
}
} catch (WakeupException ignore) {
} catch (Exception e) {
if (exceptionHandler != null) {
exceptionHandler.handle(e);
}
}
}
});
}
示例11: pollMessages
import org.apache.kafka.common.errors.WakeupException; //導入依賴的package包/類
/**
* Start to poll message from broker
*/
public synchronized void pollMessages(AtomicBoolean closed){
try {
while (!closed.get()) {
ConsumerRecords<K, V> records = consumer.poll(ConsumerInit.POLL_TIMEOUT);
for (ConsumerRecord<K, V> record : records) {
handler.dealMessage(record.value());
consumer.commitSync();
}
}
} catch (WakeupException e) {
if (!closed.get()){
throw e;
}
} finally {
consumer.close();
}
}
示例12: acceptMessages
import org.apache.kafka.common.errors.WakeupException; //導入依賴的package包/類
private void acceptMessages() {
consumer.subscribe(singletonList(topic));
while (!stop.get()) {
ConsumerRecords<String, String> records;
try {
records = consumer.poll(1000);
} catch (WakeupException e) {
if (!stop.get()) throw e;
continue;
}
for (ConsumerRecord<String, String> record : records) {
acceptMessage(record);
long offsetToCommit = record.offset() + 1;
consumer.commitSync(singletonMap(
new TopicPartition(record.topic(), record.partition()),
new OffsetAndMetadata(offsetToCommit)));
}
}
}
示例13: run
import org.apache.kafka.common.errors.WakeupException; //導入依賴的package包/類
@Override
public void run() {
try {
LOG.info("Configuring KafkaConsumer on thread: {} to subscribe to topic: {}", threadNumber, topic);
consumer.subscribe(Arrays.asList(topic));
while (!closed.get()) {
final ConsumerRecords<String, CommandNotification> records = consumer.poll(10000);
// Handle new records
for(final ConsumerRecord<String, CommandNotification> record: records) {
final CommandNotification notification = record.value();
LOG.info("Thread {} is adding notification: {}", threadNumber, notification);
coord.processNextCommandNotification(notification);
}
}
LOG.info("Finished polling.");
} catch (final WakeupException e) {
// Ignore exception if closing
if (!closed.get()) {
throw e;
}
} finally {
consumer.close();
}
}
示例14: consume
import org.apache.kafka.common.errors.WakeupException; //導入依賴的package包/類
private void consume() {
try {
Thread.currentThread().setName(
"JMKafkaConsumer-" + OS.getHostname() + "-" + groupId);
subscribe(topics);
while (isRunning()) {
handleConsumerRecords(poll(pollIntervalMs));
checkPauseStatus();
}
} catch (WakeupException e) {
if (isRunning())
JMExceptionManager.logException(log, e, "consume");
} finally {
super.close();
}
}
示例15: close
import org.apache.kafka.common.errors.WakeupException; //導入依賴的package包/類
@Override
public void close() {
try {
if(!isShutdown.get()) {
super.close();
isShutdown.set(true);
}
}
catch(WakeupException we) {
//see https://issues.apache.org/jira/browse/STORM-2184
LOG.warn("You can generally ignore these, as per https://issues.apache.org/jira/browse/STORM-2184 -- {}", we.getMessage(), we);
}
catch(IllegalStateException ise) {
if(ise.getMessage().contains("This consumer has already been closed")) {
LOG.warn(ise.getMessage());
}
else {
throw ise;
}
}
}