本文整理匯總了Java中org.apache.kafka.streams.KafkaStreams.metadataForKey方法的典型用法代碼示例。如果您正苦於以下問題:Java KafkaStreams.metadataForKey方法的具體用法?Java KafkaStreams.metadataForKey怎麽用?Java KafkaStreams.metadataForKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.kafka.streams.KafkaStreams
的用法示例。
在下文中一共展示了KafkaStreams.metadataForKey方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getMachineMetric
import org.apache.kafka.streams.KafkaStreams; //導入方法依賴的package包/類
/**
* Metrics for a machine
*
* @param machine
* @return the metric
*/
@GET
@Path("{machine}")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public Response getMachineMetric(@PathParam("machine") String machine) {
LOGGER.log(Level.INFO, "Fetching metrics for machine {0}", machine);
KafkaStreams ks = GlobalAppState.getInstance().getKafkaStreams();
HostInfo thisInstance = GlobalAppState.getInstance().getHostPortInfo();
Metrics metrics = null;
StreamsMetadata metadataForMachine = ks.metadataForKey(storeName, machine, new StringSerializer());
if (metadataForMachine.host().equals(thisInstance.host()) && metadataForMachine.port() == thisInstance.port()) {
LOGGER.log(Level.INFO, "Querying local store for machine {0}", machine);
metrics = getLocalMetrics(machine);
} else {
//LOGGER.log(Level.INFO, "Querying remote store for machine {0}", machine);
String url = "http://" + metadataForMachine.host() + ":" + metadataForMachine.port() + "/metrics/remote/" + machine;
metrics = Utils.getRemoteStoreState(url, 2, TimeUnit.SECONDS);
LOGGER.log(Level.INFO, "Metric from remote store at {0} == {1}", new Object[]{url, metrics});
}
return Response.ok(metrics).build();
}