All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.otto.synapse.eventsource.EventSource Maven / Gradle / Ivy

Go to download

A library used at otto.de to implement Spring Boot based event-sourcing microservices.

There is a newer version: 0.33.1
Show newest version
package de.otto.synapse.eventsource;

import de.otto.synapse.channel.ChannelPosition;
import de.otto.synapse.channel.ShardResponse;
import de.otto.synapse.consumer.MessageConsumer;
import de.otto.synapse.consumer.MessageDispatcher;
import de.otto.synapse.endpoint.receiver.MessageLogReceiverEndpoint;
import de.otto.synapse.message.Message;

import javax.annotation.Nonnull;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.function.Predicate;

import static de.otto.synapse.channel.StopCondition.shutdown;

/**
 * An event source of {@link Message events}.
 * 

* Event sources can be consumed by {@link Consumer consumers}. *

* */ public interface EventSource { /** * Registers a new EventConsumer at the EventSource. * * {@link MessageConsumer consumers} have to be thread safe as it may be called from multiple threads * (e.g. for kinesis streams there is one thread per shard) * * @param messageConsumer registered EventConsumer */ void register(MessageConsumer messageConsumer); /** * Returns the MessageDispatcher used by the EventSource to translate and sent incoming messages to the * registered {@link MessageConsumer message consumers}. * * @return MessageDispatcher */ @Nonnull MessageDispatcher getMessageDispatcher(); /** * Returns the MessageLogReceiverEndpoint used by the {@code EventSource} to consume events. * * @return MessageLogReceiverEndpoint */ @Nonnull MessageLogReceiverEndpoint getMessageLogReceiverEndpoint(); /** * Returns the name of the EventSource. *

* For streaming event-sources, this is the name of the event stream. *

* * @return name */ String getChannelName(); /** * Consumes all events from the EventSource, until the (current) end of the stream is reached. *

* The registered {@link MessageConsumer consumers} will be called zero or more times, depending on * the number of events retrieved from the EventSource. *

* * @return the new read position */ default CompletableFuture consume() { return consumeUntil(shutdown()); } /** * Consumes all messages from the EventSource until the predicate returns true. *

* The registered {@link MessageConsumer consumers} will be called zero or more times, depending on * the number of messages retrieved from the EventSource. *

* * @param stopCondition the stop condition used to determine whether or not message-consumption should stop * @return the new read position */ @Nonnull CompletableFuture consumeUntil(final @Nonnull Predicate stopCondition); void stop(); boolean isStopping(); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy