tag | e488cab4a491e73d72e495f517e9a7ed798e22ab | |
---|---|---|
tagger | Luca Milanesio <luca.milanesio@gmail.com> | Mon May 02 09:43:02 2022 +0100 |
object | 46bde3fa09364328d349956da258b28f07e3d53b |
v3.5.0.1
commit | 46bde3fa09364328d349956da258b28f07e3d53b | [log] [tgz] |
---|---|---|
author | Luca Milanesio <luca.milanesio@gmail.com> | Fri Dec 17 19:12:13 2021 +0000 |
committer | Luca Milanesio <luca.milanesio@gmail.com> | Fri Dec 17 19:12:13 2021 +0000 |
tree | 14ed198e677872a89995c7bb12501c48eee2dbf4 | |
parent | 63f367e8e7d1313475dd2d53f6d374a521f60cb6 [diff] |
Set project and Gerrit version to v3.5.0.1 Change-Id: I0080c7c60615cb052b5af5dfef71912dfcfbda41
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); } }
Alternative way to setup Stream Event Publisher is to use default Guice module:
import com.gerritforge.gerrit.eventbroker.publisher.StreamEventPublisherModule; import com.google.inject.AbstractModule; import com.google.inject.TypeLiteral; import com.google.inject.name.Names; 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)); install(new StreamEventPublisherModule()); } }
Note: To avoid message duplication Stream Events Publisher uses gerrit.instanceId and Event.instanceId to filter out forwarded events.
When StreamEventPublisher
is used user can optionally bind an implementation of the BrokerMetrics` interface. This will allow to collect metrics about successful/failure stream events publishing. If no binding is provided default implementation will skip collecting metrics:
import com.google.gerrit.extensions.registration.DynamicItem; import com.google.inject.AbstractModule; public class SomeModule extends AbstractModule { @Override protected void configure() { DynamicItem.bind(binder(), BrokerMetrics.class) .to(BrokerMetricsImpl.class) .in(Scopes.SINGLETON); } }
Note: BrokerMetrics
implementation must be bound in a plugin module.