use of io.confluent.ksql.rest.client.StreamPublisher in project ksql by confluentinc.
the class Cli method handlePrintedTopic.
@SuppressWarnings({ "try", "unused" })
private void handlePrintedTopic(final String printTopic, final SqlBaseParser.PrintTopicContext ignored) {
final RestResponse<StreamPublisher<String>> topicResponse = makeKsqlRequest(printTopic, restClient::makePrintTopicRequest);
if (topicResponse.isSuccessful()) {
try (StatusClosable toClose = terminal.setStatusMessage("Press CTRL-C to interrupt")) {
final CompletableFuture<Void> future = new CompletableFuture<>();
final StreamPublisher<String> publisher = topicResponse.getResponse();
final PrintTopicSubscriber subscriber = new PrintTopicSubscriber(publisher.getContext(), future);
publisher.subscribe(subscriber);
terminal.handle(Terminal.Signal.INT, signal -> {
terminal.handle(Terminal.Signal.INT, Terminal.SignalHandler.SIG_IGN);
subscriber.close();
future.complete(null);
});
try {
future.get();
} catch (Exception e) {
LOGGER.error("Unexpected exception in waiting for print topic completion", e);
} finally {
publisher.close();
}
terminal.writer().println("Topic printing ceased");
}
} else {
terminal.writer().println(topicResponse.getErrorMessage().getMessage());
}
terminal.flush();
}
use of io.confluent.ksql.rest.client.StreamPublisher in project ksql by confluentinc.
the class Cli method handleQuery.
// ignored param is required to compile.
@SuppressWarnings({ "try", "unused" })
private void handleQuery(final String statement, final SqlBaseParser.QueryStatementContext query) {
final RestResponse<StreamPublisher<StreamedRow>> queryResponse = makeKsqlRequest(statement, restClient::makeQueryRequestStreamed);
if (!queryResponse.isSuccessful()) {
terminal.printErrorMessage(queryResponse.getErrorMessage());
terminal.flush();
} else {
try (StatusClosable toClose = terminal.setStatusMessage("Press CTRL-C to interrupt")) {
final StreamPublisher<StreamedRow> publisher = queryResponse.getResponse();
final CompletableFuture<Void> future = new CompletableFuture<>();
final QueryStreamSubscriber subscriber = new QueryStreamSubscriber(publisher.getContext(), future);
publisher.subscribe(subscriber);
terminal.handle(Terminal.Signal.INT, signal -> {
terminal.handle(Terminal.Signal.INT, Terminal.SignalHandler.SIG_IGN);
subscriber.close();
future.complete(null);
});
try {
if (streamedQueryTimeoutMs != null) {
future.get(streamedQueryTimeoutMs, TimeUnit.MILLISECONDS);
} else {
future.get();
}
} catch (Exception e) {
LOGGER.error("Unexpected exception in waiting for query", e);
} finally {
terminal.writer().println("Query terminated");
terminal.flush();
publisher.close();
}
}
}
}
use of io.confluent.ksql.rest.client.StreamPublisher in project ksql by confluentinc.
the class ConsistencyOffsetVectorFunctionalTest method shouldRoundTripCVWhenPullQueryHttp1.
@Test(timeout = 120000L)
public void shouldRoundTripCVWhenPullQueryHttp1() throws Exception {
// Given
final KsqlRestClient ksqlRestClient = REST_APP.buildKsqlClient(Optional.empty(), ConsistencyLevel.MONOTONIC_SESSION);
// When
final RestResponse<StreamPublisher<StreamedRow>> response = ksqlRestClient.makeQueryRequestStreamed(PULL_QUERY_ON_TABLE, 1L, null, null);
final List<StreamedRow> rows = getElementsFromPublisher(4, response.getResponse());
// Then
assertThat(rows, hasSize(3));
assertThat(rows.get(2).getConsistencyToken().get(), not(Optional.empty()));
final String serialized = rows.get(2).getConsistencyToken().get().getConsistencyToken();
verifyConsistencyVector(serialized);
}
use of io.confluent.ksql.rest.client.StreamPublisher in project ksql by confluentinc.
the class ConsistencyOffsetVectorFunctionalTest method shouldNotRoundTripCVHttp1.
@Test(timeout = 120000L)
public void shouldNotRoundTripCVHttp1() throws Exception {
final KsqlRestClient ksqlRestClient = REST_APP.buildKsqlClient(Optional.empty(), ConsistencyLevel.EVENTUAL);
final RestResponse<StreamPublisher<StreamedRow>> response = ksqlRestClient.makeQueryRequestStreamed(PULL_QUERY_ON_TABLE, 1L);
final List<StreamedRow> rows = getElementsFromPublisher(4, response.getResponse());
assertThat(rows, hasSize(2));
assertThat(rows.get(0).getConsistencyToken(), is(Optional.empty()));
assertThat(rows.get(1).getConsistencyToken(), is(Optional.empty()));
}
Aggregations