void readSingleBatch() throws IOException { try (final JsonInput jsonInput = openJsonInput()) { final JsonParser jsonParser = jsonInput.getJsonParser(); readBatch(jsonParser); } catch (IOException e) { metricsCollector.markErrorWhileConsuming(); throw e; } }
@Override public final <T> IORunnable runnable(Class<T> eventClass, Listener<T> listener) { final EventReader<T> eventReader = new MappingEventReader<>(eventClass, objectMapper); return runnable(eventReader, listener); }
@Override public void run() throws IOException { try { runInternal(); } catch (BackoffException e) { throw e.getCause(); } }
@Override public final <T> IORunnable runnable(EventReader<T> eventReader, Listener<T> listener) { final StreamParameters streamParameters = this.streamParameters != null ? this.streamParameters : new StreamParameters(); final String queryString = streamParameters.toQueryString(); final URI uri = getURI(queryString); final Set<String> eventNames = getEventNames(); final Optional<Subscription> subscription = getSubscription(); final Optional<Lock> lock = getLock(); final BackoffStrategy backoffStrategy = this.backoffStrategy != null ? this.backoffStrategy : new EqualJitterBackoffStrategy(); final MetricsCollector metricsCollector = this.metricsCollector != null ? this.metricsCollector : NoMetricsCollector.NO_METRICS_COLLECTOR; final BatchHandler batchHandler = this.batchHandler != null ? this.batchHandler : DefaultBatchHandler.INSTANCE; return new NakadiReader<>(uri, requestFactory, backoffStrategy, cursorManager, eventNames, subscription, lock, eventReader, listener, batchHandler, metricsCollector); }
public NakadiClient build() { final RequestFactory clientHttpRequestFactory = wrapClientHttpRequestFactory(this.clientHttpRequestFactory != null ? this.clientHttpRequestFactory : defaultClientHttpRequestFactory(), accessTokenProvider); final CursorManager cursorManager = this.cursorManager != null ? this.cursorManager : new ManagedCursorManager(baseUri, clientHttpRequestFactory, true); final ObjectMapper objectMapper = this.objectMapper != null ? this.objectMapper : DefaultObjectMapper.INSTANCE; return new NakadiClient(baseUri, clientHttpRequestFactory, objectMapper, cursorManager); } }
/** * Create a subscription for a single event type. * * @deprecated Use the {@link SubscriptionBuilder} and {@link NakadiClient#subscription(String, String)} instead. */ @Deprecated public Subscription subscribe(String applicationName, String eventName, String consumerGroup) throws IOException { return subscription(applicationName, eventName).withConsumerGroup(consumerGroup).subscribe(); }
public SubscriptionBuilder readFromBegin() { checkState(initialCursors == null, "Initial cursors can not be specified when reading from 'begin'"); return new SubscriptionBuilder(nakadiClient, applicationName, eventNames, consumerGroup, SubscriptionRequest.Position.BEGIN, null); }
public SubscriptionBuilder readFromCursors(List<Cursor> initialCursors) { checkArgument(initialCursors != null, "Initial cursors have to be specified"); return new SubscriptionBuilder(nakadiClient, applicationName, eventNames, consumerGroup, SubscriptionRequest.Position.CURSORS, initialCursors); }
public StreamBuilder.SubscriptionStreamBuilder stream(Subscription subscription) { checkState(cursorManager instanceof ManagedCursorManager, "Subscription api requires a ManagedCursorManager"); return new StreamBuilders.SubscriptionStreamBuilderImpl(baseUri, clientHttpRequestFactory, cursorManager, objectMapper, subscription); }
public EqualJitterBackoffStrategy withMaxRetries(int maxRetries) { return new EqualJitterBackoffStrategy(super.withMaxRetries(maxRetries)); }
public FullJitterBackoffStrategy withMaxRetries(int maxRetries) { return new FullJitterBackoffStrategy(super.withMaxRetries(maxRetries)); }
static RequestFactory wrapClientHttpRequestFactory(RequestFactory delegate, @Nullable AccessTokenProvider accessTokenProvider) { RequestFactory requestFactory = new ProblemHandlingRequestFactory(delegate); if (accessTokenProvider != null) { requestFactory = new AuthorizedRequestFactory(requestFactory, accessTokenProvider); } return requestFactory; }
@Override public SubscriptionStreamBuilder withObjectMapper(ObjectMapper objectMapper) { return new SubscriptionStreamBuilderImpl(baseUri, requestFactory, cursorManager, objectMapper, backoffStrategy, streamParameters, batchHandler, metricsCollector, subscription); } }
@Override public void onSuccess(String eventName, List<Cursor> cursors) throws IOException { for (Cursor cursor : cursors) { onSuccess(eventName, cursor); } }
/** * Maximum amount of seconds that nakadi will be waiting for commit after sending a batch to a client. * If the commit does not come within this timeout, nakadi will initialize stream termination, no * new data will be sent. Partitions from this stream will be assigned to other streams. * * @param commitTimeout */ public StreamParameters withCommitTimeout(int commitTimeout) { return new StreamParameters(batchLimit, streamLimit, batchFlushTimeout, streamTimeout, streamKeepAliveLimit, maxUncommittedEvents, commitTimeout); }
public SubscriptionBuilder readFromEnd() { checkState(initialCursors == null, "Initial cursors can not be specified when reading from 'end'"); return new SubscriptionBuilder(nakadiClient, applicationName, eventNames, consumerGroup, SubscriptionRequest.Position.END, null); }
@Override public SubscriptionStreamBuilder withBackoffStrategy(BackoffStrategy backoffStrategy) { return new SubscriptionStreamBuilderImpl(baseUri, requestFactory, cursorManager, objectMapper, backoffStrategy, streamParameters, batchHandler, metricsCollector, subscription); }
@Override public SubscriptionStreamBuilder withStreamParameters(StreamParameters streamParameters) { return new SubscriptionStreamBuilderImpl(baseUri, requestFactory, cursorManager, objectMapper, backoffStrategy, streamParameters, batchHandler, metricsCollector, subscription); }