Class SimpleCommandHandlingComponent

java.lang.Object
org.axonframework.messaging.commandhandling.SimpleCommandHandlingComponent
All Implemented Interfaces:
DescribableComponent, CommandHandler, CommandHandlerRegistry<SimpleCommandHandlingComponent>, CommandHandlingComponent, MessageHandler

public class SimpleCommandHandlingComponent extends Object implements CommandHandlingComponent, CommandHandlerRegistry<SimpleCommandHandlingComponent>
A simple implementation of the 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 Details

    • create

      public static SimpleCommandHandlingComponent create(@Nonnull String name)
      Instantiates a simple CommandHandlingComponent that is able to handle commands and delegate them to subcomponents.
      Parameters:
      name - The name of the component, used for describing the component.
      Returns:
      A simple CommandHandlingComponent instance with the given name.
    • subscribe

      public SimpleCommandHandlingComponent subscribe(@Nonnull QualifiedName name, @Nonnull CommandHandler commandHandler)
      Description copied from interface: CommandHandlerRegistry
      Subscribe the given handler for commands of the given name.

      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 new handler gets the subscription.

      Specified by:
      subscribe in interface CommandHandlerRegistry<SimpleCommandHandlingComponent>
      Parameters:
      name - The name the given commandHandler can handle.
      commandHandler - The handler instance that handles commands for the given name.
      Returns:
      This registry for fluent interfacing.
    • subscribe

      public SimpleCommandHandlingComponent subscribe(@Nonnull CommandHandlingComponent commandHandlingComponent)
      Description copied from interface: CommandHandlerRegistry
      Subscribe the given handlingComponent with this registry.

      Typically invokes CommandHandlerRegistry.subscribe(Set, CommandHandler), using the CommandHandlingComponent.supportedCommands() as the set of compatible names the component in question can deal with.

      If a subscription already exists for any name in the supported command names, the behavior is undefined. Implementations may throw an exception to refuse duplicate subscription or alternatively decide whether the existing or new handler gets the subscription.

      Specified by:
      subscribe in interface CommandHandlerRegistry<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: CommandHandler
      Handles the given command within the given context.

      The result message in the returned stream may be null. Only a single or empty result message should ever be expected.

      Specified by:
      handle in interface CommandHandler
      Parameters:
      command - The command to handle.
      context - The context to the given command is handled in.
      Returns:
      A MessagesStream.Single of a CommandResultMessage.
    • describeTo

      public void describeTo(@Nonnull ComponentDescriptor descriptor)
      Description copied from interface: DescribableComponent
      Describe the properties of this DescribableComponent with the given descriptor.

      Components should call the appropriate describeProperty methods 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 DescribableComponent implementation 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 the describeTo method, 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:
      describeTo in interface DescribableComponent
      Parameters:
      descriptor - The component descriptor to describe this DescribableComponentn its properties in.
    • supportedCommands

      public Set<QualifiedName> supportedCommands()
      Description copied from interface: CommandHandlingComponent
      All supported commands, referenced through a QualifiedName.
      Specified by:
      supportedCommands in interface CommandHandlingComponent
      Returns:
      All supported commands, referenced through a QualifiedName.