當前位置: 首頁>>代碼示例>>Java>>正文


Java WakeupException類代碼示例

本文整理匯總了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();
    }
}
 
開發者ID:Zephery,項目名稱:newblog,代碼行數:21,代碼來源:KafkaConsumerRunner.java

示例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();
	}
}
 
開發者ID:netkiller,項目名稱:ipo,代碼行數:21,代碼來源:KafkaConsumerThread.java

示例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();
    }
}
 
開發者ID:jeqo,項目名稱:talk-kafka-messaging-logs,代碼行數:22,代碼來源:ConsumerLoop.java

示例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();
    }
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:25,代碼來源:VerifiableConsumer.java

示例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();
  }
}
 
開發者ID:datamachines,項目名稱:KafkaToSQS,代碼行數:18,代碼來源:ConsumerLoop.java

示例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
        }
    }
}
 
開發者ID:NewTranx,項目名稱:newtranx-utils,代碼行數:18,代碼來源:BasicKafkaAsyncResponseBroker.java

示例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;
        }
    }
 
開發者ID:jretty-org,項目名稱:kafka-xclient,代碼行數:23,代碼來源:AbstractConsumerThread.java

示例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);
}
 
開發者ID:iotoasis,項目名稱:SO,代碼行數:26,代碼來源:AGenericConsumerHandler.java

示例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();
    }
}
 
開發者ID:iotoasis,項目名稱:SO,代碼行數:23,代碼來源:AGenericConsumerHandler2.java

示例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);
        }
      }
    }
  });
}
 
開發者ID:vert-x3,項目名稱:vertx-kafka-client,代碼行數:21,代碼來源:KafkaReadStreamImpl.java

示例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();
       }
}
 
開發者ID:sn3009,項目名稱:EasyMessage,代碼行數:21,代碼來源:ConsumerEngineBootServer.java

示例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)));
        }
    }
}
 
開發者ID:andreschaffer,項目名稱:microservices-testing-examples,代碼行數:20,代碼來源:WelcomeEmailConsumer.java

示例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();
    }
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:26,代碼來源:PeriodicNotificationConsumer.java

示例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();
	}
}
 
開發者ID:JM-Lab,項目名稱:utils-kafka,代碼行數:17,代碼來源:JMKafkaConsumer.java

示例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;
    }
  }
}
 
開發者ID:apache,項目名稱:metron,代碼行數:22,代碼來源:StormKafkaSpout.java


注:本文中的org.apache.kafka.common.errors.WakeupException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。