commit | fec27cee2d281e6b22974fe75e73a988b749fdb0 | [log] [tgz] |
---|---|---|
author | Alvaro Vilaplana Garcia <alvaro.vilaplana@gmail.com> | Thu Sep 21 10:11:08 2023 +0100 |
committer | Alvaro Vilaplana Garcia <alvaro.vilaplana@gmail.com> | Thu Sep 21 10:11:08 2023 +0100 |
tree | 29ddd45eca8d53970468df747a98013e0276bfe8 | |
parent | 47b1892936eb272555873fd6ba3c483bedfa936c [diff] | |
parent | 79881fcf069497fe0e30c9545fa1a787e49975c6 [diff] |
Merge branch 'stable-3.8' * stable-3.8: Set project and Gerrit version to v3.5.6 Remove Maven legacy pom.xml Make events-broker a Gerrit plugin Provide subscribers with consumer's group id Remove actual implementation of InProcessBrokerApi Set event-broker and gerrit version to v3.4.8 Add interface ExtendedBrokerApi to consume messages with groupId Change the build result name to events-broker.jar Bump version to 3.7.2 Set version to 3.6.3 Change-Id: I2d7c9fa0cb21031681bc539348923c31b77d7889
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 java.util.concurrent.Executor; import com.gerritforge.gerrit.eventbroker.publisher.StreamEventPublisher; import com.gerritforge.gerrit.eventbroker.publisher.StreamEventPublisherConfig; import com.gerritforge.gerrit.eventbroker.publisher.executor.StreamEventPublisherExecutor; import com.gerritforge.gerrit.eventbroker.publisher.executor.StreamEventPublisherExecutorProvider; 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 StreamEventPublisherModule
:
import com.gerritforge.gerrit.eventbroker.publisher.StreamEventPublisherConfig; 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.