Class SimpleCommandHandlingComponent
- All Implemented Interfaces:
DescribableComponent,CommandHandler,CommandHandlerRegistry<SimpleCommandHandlingComponent>,CommandHandlingComponent,MessageHandler
CommandHandlingComponent interface, allowing for easy registration of
CommandHandlers and other CommandHandlingComponents.
Registered subcomponents are preferred over registered command handlers when handling a command.
- Since:
- 5.0.0
- Author:
- Allard Buijze, Mitchell Herrijgers, Steven van Beelen, Mateusz Nowak
-
Method Summary
Modifier and TypeMethodDescriptionInstantiates a simpleCommandHandlingComponentthat is able to handle commands and delegate them to subcomponents.voiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.handle(CommandMessage command, ProcessingContext context) Handles the givencommandwithin the givencontext.subscribe(CommandHandlingComponent commandHandlingComponent) Subscribe the givenhandlingComponentwith this registry.subscribe(QualifiedName name, CommandHandler commandHandler) All supportedcommands, referenced through aQualifiedName.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.messaging.commandhandling.CommandHandlerRegistry
subscribe
-
Method Details
-
create
Instantiates a simpleCommandHandlingComponentthat is able to handle commands and delegate them to subcomponents.- Parameters:
name- The name of the component, used fordescribingthe component.- Returns:
- A simple
CommandHandlingComponentinstance with the givenname.
-
subscribe
public SimpleCommandHandlingComponent subscribe(@Nonnull QualifiedName name, @Nonnull CommandHandler commandHandler) Description copied from interface:CommandHandlerRegistrySubscribe the givenhandlerforcommandsof the givenname.If a subscription already exists for the
name, the behavior is undefined. Implementations may throw an exception to refuse duplicate subscription or alternatively decide whether the existing or newhandlergets the subscription.- Specified by:
subscribein interfaceCommandHandlerRegistry<SimpleCommandHandlingComponent>- Parameters:
name- The name the givencommandHandlercan handle.commandHandler- The handler instance that handlescommandsfor the given name.- Returns:
- This registry for fluent interfacing.
-
subscribe
public SimpleCommandHandlingComponent subscribe(@Nonnull CommandHandlingComponent commandHandlingComponent) Description copied from interface:CommandHandlerRegistrySubscribe the givenhandlingComponentwith this registry.Typically invokes
CommandHandlerRegistry.subscribe(Set, CommandHandler), using theCommandHandlingComponent.supportedCommands()as the set of compatiblenamesthe component in question can deal with.If a subscription already exists for any
namein the supported command names, the behavior is undefined. Implementations may throw an exception to refuse duplicate subscription or alternatively decide whether the existing or newhandlergets the subscription.- Specified by:
subscribein interfaceCommandHandlerRegistry<SimpleCommandHandlingComponent>- Parameters:
commandHandlingComponent- The command handling component instance to subscribe with this registry.- Returns:
- This registry for fluent interfacing.
-
handle
@Nonnull public MessageStream.Single<CommandResultMessage> handle(@Nonnull CommandMessage command, @Nonnull ProcessingContext context) Description copied from interface:CommandHandlerHandles the givencommandwithin the givencontext.The
result messagein the returnedstreammay benull. Only asingleoremptyresult message should ever be expected.- Specified by:
handlein interfaceCommandHandler- Parameters:
command- The command to handle.context- The context to the givencommandis handled in.- Returns:
- A
MessagesStream.Singleof aCommandResultMessage.
-
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.
-
supportedCommands
Description copied from interface:CommandHandlingComponentAll supportedcommands, referenced through aQualifiedName.- Specified by:
supportedCommandsin interfaceCommandHandlingComponent- Returns:
- All supported
commands, referenced through aQualifiedName.
-