Interface EventStreamClientFactory

  • All Superinterfaces:
    java.lang.AutoCloseable
    All Known Implementing Classes:
    AbstractClientFactoryImpl, ClientFactoryImpl

    public interface EventStreamClientFactory
    extends java.lang.AutoCloseable
    Used to create Writers and Readers operating on a stream.

    Events that are written to a stream can be read by a reader. All events can be processed with exactly once semantics provided the reader has the ability to restore to the correct position upon failure. See EventRead.getPosition()

    A note on ordering: Events inside of a stream have an order, but may need to be divided between multiple readers for scaling. In order to process events in parallel on different hosts and still have some ordering guarantees; events written to a stream have a routingKey see EventStreamWriter.writeEvent(String, Object). Events with the same routing key are delivered to a reader in order serially (i.e. They must go the the same reader or its replacement). However because ReaderGroups process events in parallel there is no ordering between events sent to different routing keys because these may end up on different readers.

    A note on scaling: Because a stream can grow in its event rate, streams are divided into Segments. For the most part this is an implementation detail. However its worth understanding that the way a stream is divided between multiple readers in a group that wish to split the messages between them is by giving different segments to different readers.

    • Method Detail

      • withScope

        static EventStreamClientFactory withScope​(java.lang.String scope,
                                                  ClientConfig config)
        Creates a new instance of Client Factory.
        Parameters:
        scope - The scope string.
        config - Configuration for the client.
        Returns:
        Instance of ClientFactory implementation.
      • createEventWriter

        <T> EventStreamWriter<T> createEventWriter​(java.lang.String streamName,
                                                   Serializer<T> s,
                                                   EventWriterConfig config)
        Creates a new writer that can write to the specified stream. Uses an autogenerated writerId to refer to this writer.
        Type Parameters:
        T - The type of events.
        Parameters:
        streamName - The name of the stream to write to.
        s - The Serializer.
        config - The writer configuration.
        Returns:
        Newly created writer object
      • createEventWriter

        <T> EventStreamWriter<T> createEventWriter​(java.lang.String writerId,
                                                   java.lang.String streamName,
                                                   Serializer<T> s,
                                                   EventWriterConfig config)
        Creates a new writer that can write to the specified stream.
        Type Parameters:
        T - The type of events.
        Parameters:
        writerId - An name which identifies this writer.
        streamName - The name of the stream to write to.
        s - The Serializer.
        config - The writer configuration.
        Returns:
        Newly created writer object
      • createTransactionalEventWriter

        <T> TransactionalEventStreamWriter<T> createTransactionalEventWriter​(java.lang.String writerId,
                                                                             java.lang.String streamName,
                                                                             Serializer<T> s,
                                                                             EventWriterConfig config)
        Creates a new transactional writer that can write to the specified stream atomically.
        Type Parameters:
        T - The type of events.
        Parameters:
        writerId - An name which identifies this writer.
        streamName - The name of the stream to write to.
        config - The writer configuration.
        s - The Serializer.
        Returns:
        Newly created writer object
      • createTransactionalEventWriter

        <T> TransactionalEventStreamWriter<T> createTransactionalEventWriter​(java.lang.String streamName,
                                                                             Serializer<T> s,
                                                                             EventWriterConfig config)
        Creates a new transactional writer that can write to the specified stream atomically. Uses an autogenerated writerId to refer to this writer.
        Type Parameters:
        T - The type of events.
        Parameters:
        streamName - The name of the stream to write to.
        config - The writer configuration.
        s - The Serializer.
        Returns:
        Newly created writer object
      • createReader

        <T> EventStreamReader<T> createReader​(java.lang.String readerId,
                                              java.lang.String readerGroup,
                                              Serializer<T> s,
                                              ReaderConfig config)
        Creates (or recreates) a new reader that is part of a ReaderGroup. The reader will join the group and the members of the group will automatically rebalance among themselves. In the event that the reader dies, the method ReaderGroup.readerOffline(String, Position) should be called, passing the last position of the reader (Usually done by storing the position along with the output when it is processed.) Which will trigger redistribute the events among the remaining readers.

        Note that calling reader offline while the reader is still online may result in multiple readers within the group receiving the same events.

        Type Parameters:
        T - The type of events.
        Parameters:
        readerId - A unique name (within the group) for this reader.
        readerGroup - The name of the group to join.
        s - The serializer for events.
        config - The reader's configuration.
        Returns:
        Newly created reader object that is a part of reader group
      • close

        void close()
        Closes the client factory. This will close any connections created through it.
        Specified by:
        close in interface java.lang.AutoCloseable
        See Also:
        AutoCloseable.close()