Class SubscribingEventProcessor
- All Implemented Interfaces:
DescribableComponent,EventProcessor
subscribes to the EventBus for
events. Events published on the event bus are supplied to this processor in the publishing thread.
- Since:
- 3.0.0
- Author:
- Rene de Waele
-
Constructor Summary
ConstructorsConstructorDescriptionSubscribingEventProcessor(String name, List<EventHandlingComponent> eventHandlingComponents, SubscribingEventProcessorConfiguration configuration) Instantiate aSubscribingEventProcessorwith givenname,eventHandlingComponentsand based on the fields contained in theSubscribingEventProcessorConfiguration. -
Method Summary
Modifier and TypeMethodDescriptionvoiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.booleanisError()Indicates whether the processor has been shut down due to an error.booleanIndicates whether this processor is currently running (i.e. consuming events from its message source).name()Returns the name of this event processor.protected voidprocess(List<EventMessage> eventMessages, ProcessingContext context) Process the given messages.shutdown()Shut down this processor.start()Start this processor.
-
Constructor Details
-
SubscribingEventProcessor
public SubscribingEventProcessor(@Nonnull String name, @Nonnull List<EventHandlingComponent> eventHandlingComponents, @Nonnull SubscribingEventProcessorConfiguration configuration) Instantiate aSubscribingEventProcessorwith givenname,eventHandlingComponentsand based on the fields contained in theSubscribingEventProcessorConfiguration.Will assert the following for their presence in the configuration, prior to constructing this processor:
If any of these is not present or does not comply to the requirements anAxonConfigurationExceptionis thrown.- Parameters:
name- AStringdefining thisEventProcessorinstance.eventHandlingComponents- TheEventHandlingComponents which will handle all the individualEventMessages.configuration- TheSubscribingEventProcessorConfigurationused to configure aSubscribingEventProcessorinstance.
-
-
Method Details
-
name
Description copied from interface:EventProcessorReturns the name of this event processor. This name is used to detect distributed instances of the same event processor. Multiple instances referring to the same logical event processor (on different JVM's) must have the same name.- Specified by:
namein interfaceEventProcessor- Returns:
- the name of this event processor
-
start
Start this processor. This will register the processor with theEventBus.Upon start up of an application, this method will be invoked in the
Phase.LOCAL_MESSAGE_HANDLER_REGISTRATIONSphase.- Specified by:
startin interfaceEventProcessor- Returns:
- a CompletableFuture that completes when the start process is finished.
-
isRunning
public boolean isRunning()Description copied from interface:EventProcessorIndicates whether this processor is currently running (i.e. consuming events from its message source).- Specified by:
isRunningin interfaceEventProcessor- Returns:
truewhen running, otherwisefalse
-
isError
public boolean isError()Description copied from interface:EventProcessorIndicates whether the processor has been shut down due to an error. In such case, the processor has forcefully shut down, as it wasn't able to automatically recover.Note that this method returns
falsewhen the processor was stopped usingEventProcessor.shutdown().- Specified by:
isErrorin interfaceEventProcessor- Returns:
truewhen paused due to an error, otherwisefalse
-
process
protected void process(@Nonnull List<EventMessage> eventMessages, @Nullable ProcessingContext context) Process the given messages. A Unit of Work must be created for this processing.This implementation creates a Batching unit of work for the given batch of
eventMessages.- Parameters:
eventMessages- The messages to process
-
shutdown
Shut down this processor. This will deregister the processor with theEventBus.Upon shutdown of an application, this method will be invoked in the
Phase.LOCAL_MESSAGE_HANDLER_REGISTRATIONSphase.- Specified by:
shutdownin interfaceEventProcessor- Returns:
- a CompletableFuture that completes when the shutdown process is finished.
-
describeTo
Description copied from interface:DescribableComponentDescribe the properties ofthis DescribableComponentwith the givendescriptor.Components should call the appropriate
describePropertymethods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.Best Practices: As a general rule, all relevant fields of a
DescribableComponentimplementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing thedescribeTomethod, who should focus on providing information that is useful for understanding the component's configuration and state.Example implementation:
public void describeTo(ComponentDescriptor descriptor) { descriptor.describeProperty("name", this.name); descriptor.describeProperty("enabled", this.enabled); descriptor.describeProperty("configuration", this.configuration); // A nested component descriptor.describeProperty("handlers", this.eventHandlers); // A collection }- Specified by:
describeToin interfaceDescribableComponent- Parameters:
descriptor- The component descriptor to describethis DescribableComponentn its properties in.
-