commit | ee8e1e8762028bf870817fd6a878052c420ebe03 | [log] [tgz] |
---|---|---|
author | Marcin Czech <maczech@gmail.com> | Thu Aug 26 12:48:09 2021 +0200 |
committer | Marcin Czech <maczech@gmail.com> | Fri Aug 27 19:00:10 2021 +0200 |
tree | 916018d4c662c359bbaa2a148670e18910e21d11 | |
parent | 6a7af2d433f05414e14bb9736d66f186eb67921a [diff] |
Introduce timeout for stream events publishing Add message publishing timeout to avoid issue when broker is not returning ACK when publishing the message. Also move stream events publishing classes to a separate package. Bug: Issue 14909 Change-Id: Ic07689f082726550daf4b6747b393aad8c6d267d
API of a generic events broker for use with Gerrit Code Review.
Enables the de-coupling between Gerrit, plugins and the different implementations of a generic events broker.
It is a quite common use case for consumers of this library to listen for Gerrit events and to stream them on a specific topic.
Since the implementation of such logic is always the same, this library provides a generic stream events publisher which will perform the relevant operations.
In order to listen and stream gerrit events, consumers of this API need to provide a binding for the StreamEventPublisherConfig
configuration and java.util.concurrent.Executor
binding annotated with StreamEventPublisherExecutor
annotation. A default single threaded implementation (StreamEventPublisherExecutor
) is provided by the library. The last step is to explicitly bind the Stream Events Publisher, as such:
import com.gerritforge.gerrit.eventbroker.publisher.StreamEventPublisher; import com.google.gerrit.extensions.registration.DynamicSet; import com.google.gerrit.server.events.EventListener; import com.google.inject.AbstractModule; public class SomeModule extends AbstractModule { @Override protected void configure() { long messagePublishingTimeout = 1000L; bind(StreamEventPublisherConfig.class) .toInstance(new StreamEventPublisherConfig( "name_of_the_stream_events_topic", messagePublishingTimeout)); bind(Executor.class).annotatedWith(StreamEventPublisherExecutor.class).toProvider(StreamEventPublisherExecutorProvider.class); DynamicSet.bind(binder(), EventListener.class).to(StreamEventPublisher.class); } }
Note: To avoid message duplication Stream Events Publisher uses gerrit.instanceId and Event.instanceId to filter out forwarded events.