Class NakadiClient

java.lang.Object
org.zalando.fahrschein.NakadiClient

public class NakadiClient extends Object
General implementation of the Nakadi Client used within this Library.
  • Method Details

    • builder

      public static NakadiClientBuilder builder(URI baseUri, org.zalando.fahrschein.http.api.RequestFactory requestFactory)
      Returns a new Builder that will make use of the given RequestFactory.
      Parameters:
      baseUri - that we will send requests to
      requestFactory - that we use for the execution of our HTTP Requests.
      Returns:
      A builder to initialize the client. Can be further modified later.
    • getPartitions

      public List<Partition> getPartitions(String eventName) throws IOException
      Resolves a list of partitions for the given eventName.
      Parameters:
      eventName - that we want to resolve the partitions for.
      Returns:
      List<Partition> or null in
      Throws:
      IOException - in case of network issues.
    • publish

      public <T> void publish(String eventName, List<T> events) throws EventValidationException, EventPersistenceException, IOException
      Writes the given events to the endpoint provided by the eventName.

      In case of a partial success, Fahrschein will throw an EventPersistenceException`, which is retryable. In case of validation errors, which are complete failures, and should not be retried, it will throw an EventValidationException. The exceptions contain a list of individual BatchItemResponses in order of the batch items sent to Nakadi.

      These objects have the event-ids of the failed event, a publishingStatus (failed/aborted/submitted), the step where it failed and a detail string.

      Recommendation: Implement a retry-with-backoff handler for EventPersistenceExceptions, for which, depending on strong ordering consistency requirements, you either retry the full batch, or retry only the failed/aborted events.

      Type Parameters:
      T - Type of the Event
      Parameters:
      eventName - where the event should be written to
      events - that should be written
      Throws:
      IOException - in case of network errors when calling Nakadi.
      EventValidationException - in case Nakadi rejects the batch in event validation phase - should not be retried until either the event type schema or the event payload has been corrected.
      EventPersistenceException - in case Nakadi fails to persist the batch (partially). Retryable (see recommendation above).
    • subscribe

      @Deprecated public Subscription subscribe(String applicationName, String eventName, String consumerGroup) throws IOException
      Deprecated.
      Create a subscription for a single event type.
      Throws:
      IOException
    • subscription

      public SubscriptionBuilder subscription(String applicationName, String eventName) throws IOException
      Build a subscription for a single event type.
      Throws:
      IOException
    • subscription

      public SubscriptionBuilder subscription(String applicationName, Set<String> eventNames) throws IOException
      Build a subscription for multiple event types.
      Throws:
      IOException
    • deleteSubscription

      public void deleteSubscription(String subscriptionId) throws IOException
      Delete subscription based on subscription ID.
      Throws:
      IOException
    • stream

    • stream

      public StreamBuilder.LowLevelStreamBuilder stream(String eventName)