Java Code Examples for org.apache.kafka.streams.KafkaStreams#State

The following examples show how to use org.apache.kafka.streams.KafkaStreams#State . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StreamsRegistryConfiguration.java    From apicurio-registry with Apache License 2.0 6 votes vote down vote up
@Produces
@ApplicationScoped
@Current
public AsyncBiFunctionService<Void, Void, KafkaStreams.State> stateService(
    KafkaStreams streams,
    HostInfo storageLocalHost,
    LocalService<AsyncBiFunctionService.WithSerdes<Void, Void, KafkaStreams.State>> localStateService
) {
    return new DistributedAsyncBiFunctionService<>(
        streams,
        storageLocalHost,
        "stateStore",
        localStateService,
        new DefaultGrpcChannelProvider()
    );
}
 
Example 2
Source File: KafkaStorage.java    From zipkin-storage-kafka with Apache License 2.0 6 votes vote down vote up
@Override public CheckResult check() {
  try {
    KafkaFuture<String> maybeClusterId = getAdminClient().describeCluster().clusterId();
    maybeClusterId.get(1, TimeUnit.SECONDS);
    KafkaStreams.State state = getAggregationStream().state();
    if (!state.isRunning()) {
      return CheckResult.failed(
          new IllegalStateException("Aggregation stream not running. " + state));
    }
    KafkaStreams.State traceStateStore = getTraceStorageStream().state();
    if (!traceStateStore.isRunning()) {
      return CheckResult.failed(
          new IllegalStateException("Store stream not running. " + traceStateStore));
    }
    KafkaStreams.State dependencyStateStore = getDependencyStorageStream().state();
    if (!dependencyStateStore.isRunning()) {
      return CheckResult.failed(
          new IllegalStateException("Store stream not running. " + dependencyStateStore));
    }
    return CheckResult.OK;
  } catch (Exception e) {
    return CheckResult.failed(e);
  }
}
 
Example 3
Source File: StreamsRegistryConfiguration.java    From apicurio-registry with Apache License 2.0 5 votes vote down vote up
@Produces
@Singleton
public LocalService<AsyncBiFunctionService.WithSerdes<Void, Void, KafkaStreams.State>> localStateService(
    StateService localService
) {
    return new LocalService<>(
        StateService.NAME,
        localService
    );
}
 
Example 4
Source File: StreamsRegistryConfiguration.java    From apicurio-registry with Apache License 2.0 5 votes vote down vote up
@Produces
@Singleton
public AsyncBiFunctionServiceGrpc.AsyncBiFunctionServiceImplBase storageAsyncBiFunctionServiceGrpcImpl(
    LocalService<AsyncBiFunctionService.WithSerdes<String, Long, Str.Data>> localWaitForDataService,
    LocalService<AsyncBiFunctionService.WithSerdes<Void, Void, KafkaStreams.State>> localStateService
) {
    return new AsyncBiFunctionServiceGrpcLocalDispatcher(
        Arrays.asList(localWaitForDataService, localStateService)
    );
}
 
Example 5
Source File: KafkaStreamsStarter.java    From football-events with MIT License 5 votes vote down vote up
private void startStreams(KafkaStreams kafkaStreams) {
    CountDownLatch streamsStartedLatch = new CountDownLatch(1);

    // wait for consistent state
    kafkaStreams.setStateListener((newState, oldState) -> {
        logger.trace("Kafka Streams state has been changed from {} to {}", oldState, newState);

        if (oldState == KafkaStreams.State.REBALANCING && newState == KafkaStreams.State.RUNNING) {
            streamsStartedLatch.countDown();
        }
    });
    kafkaStreams.cleanUp();
    kafkaStreams.start();
    long timeout = System.currentTimeMillis() + streamsStartupTimeout;

    try {
        streamsStartedLatch.await(timeout - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupted();
    }

    KafkaStreams.State state = kafkaStreams.state();

    if (state != KafkaStreams.State.RUNNING) {
        logger.error("Unable to start Kafka Streams in {} ms, the current state is {}",
                streamsStartupTimeout, state);
        System.exit(1);
    }
}
 
Example 6
Source File: KafkaStreamsStateHealthCheck.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public HealthCheckResponse call() {
    HealthCheckResponseBuilder responseBuilder = HealthCheckResponse.named("Kafka Streams state health check");
    try {
        KafkaStreams.State state = manager.getStreams().state();
        responseBuilder.state(state.isRunningOrRebalancing())
                .withData("state", state.name());
    } catch (Exception e) {
        responseBuilder.down().withData("technical_error", e.getMessage());
    }
    return responseBuilder.build();
}
 
Example 7
Source File: KafkaStreamsService.java    From emodb with Apache License 2.0 5 votes vote down vote up
@Override
public void onChange(KafkaStreams.State newState, KafkaStreams.State oldState) {
    if (newState == KafkaStreams.State.ERROR) {
        _fatalErrorEncountered.set(true);
        _streams.close(Duration.ofMillis(1));
    } else if (newState == KafkaStreams.State.NOT_RUNNING && _fatalErrorEncountered.get()) {
        notifyFailed(_uncaughtException.get());
    }
}
 
Example 8
Source File: StreamsRegistryConfiguration.java    From apicurio-registry with Apache License 2.0 4 votes vote down vote up
public void destroyStateService(@Observes ShutdownEvent event, @Current AsyncBiFunctionService<Void, Void, KafkaStreams.State> service) {
    close(service);
}
 
Example 9
Source File: StateService.java    From apicurio-registry with Apache License 2.0 4 votes vote down vote up
@Override
public Serde<KafkaStreams.State> resSerde() {
    return new StateSerde();
}
 
Example 10
Source File: StateService.java    From apicurio-registry with Apache License 2.0 4 votes vote down vote up
@Override
public Stream<CompletionStage<KafkaStreams.State>> apply() {
    return Stream.of(apply(null, null));
}
 
Example 11
Source File: StateService.java    From apicurio-registry with Apache License 2.0 4 votes vote down vote up
@Override
public CompletionStage<KafkaStreams.State> apply(Void v1, Void v2) {
    return CompletableFuture.completedFuture(streams.state());
}
 
Example 12
Source File: StateSerde.java    From apicurio-registry with Apache License 2.0 4 votes vote down vote up
@Override
public KafkaStreams.State deserialize(String topic, byte[] data) {
    return KafkaStreams.State.valueOf(IoUtil.toString(data));
}
 
Example 13
Source File: StateSerde.java    From apicurio-registry with Apache License 2.0 4 votes vote down vote up
@Override
public byte[] serialize(String topic, KafkaStreams.State data) {
    return IoUtil.toBytes(data.toString());
}
 
Example 14
Source File: KafkaStreamsHealth.java    From micronaut-kafka with Apache License 2.0 3 votes vote down vote up
/**
 * Build down details for the stream down.
 *
 * @param message Down message
 * @param state The stream state
 * @return Map of details messages
 */
private Map<String, String> buildDownDetails(String message, KafkaStreams.State state) {
    final Map<String, String> details = new HashMap<>();
    details.put("threadState", state.name());
    details.put("error", message);
    return details;
}
 
Example 15
Source File: KafkaStreamsHealth.java    From micronaut-kafka with Apache License 2.0 2 votes vote down vote up
/**
 * Build down details for the stream down.
 *
 * @param state The stream state
 * @return Map of details messages
 */
private Map<String, String> buildDownDetails(KafkaStreams.State state) {
    return buildDownDetails("Processor appears to be down", state);
}