@Invoker
The RECQ architecture emphasizes modularity and separation of concerns. In this context, the @Invoker annotation plays a crucial role in defining classes that act as orchestrators, bridging the gap between the external world and the internal components.
Understanding @Invoker
@InvokerThe @Invoker annotation marks a class within your Evento application as an invoker. Invokers are responsible for initiating operations or invoking methods on other components within the system. They serve as a facade, offering a simplified interface for external interactions.
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Component
public @interface Invoker {
}Here's a breakdown of the annotation's definition:
@Retention(RetentionPolicy.RUNTIME): Ensures the annotation information is retained at runtime, allowing Evento to identify invoker classes.@Target(ElementType.TYPE): Specifies that the annotation can only be applied to class declarations.@Component: Inherits from the@Componentannotation, indicating that the annotated class is a component within the Evento framework.
Invokers and the RECQ Component Pattern
The RECQ pattern promotes well-defined component types. Invokers act as a bridge between the external API layer and the internal domain logic or services. They shield the complexities of the underlying architecture from external consumers.
Here are some key characteristics of invokers:
Abstraction: They provide a simplified interface for interacting with the system, often using plain Java methods (similar to a REST API).
Orchestration: They might orchestrate calls to multiple services, projections, or sagas to fulfill a specific request.
Command/Query Gateway Access: Invokers typically leverage the
CommandGatewayto send commands and theQueryGatewayto execute queries within the system.
The InvokerWrapper Class
InvokerWrapper ClassThe provided code snippet showcases the InvokerWrapper class, an abstract class often used in conjunction with @Invoker. This class serves two primary purposes:
Command/Query Gateway Access Restriction: It defines abstract methods for retrieving the
CommandGatewayandQueryGateway. In concrete invoker implementations, these methods are usually overridden to provide access only within@InvocationHandlermethods (discussed later). This ensures proper usage of the gateways within the context of handling incoming requests.Template for Gateway Access: Concrete invoker implementations can extend
InvokerWrapperand provide specific logic for retrieving the gateways within their@InvocationHandlermethods.
Invoker in Action: The DemoInvoker Example
DemoInvoker ExampleThe provided DemoInvoker class demonstrates how @Invoker is used:
It extends
InvokerWrapper.It defines several methods annotated with
@InvocationHandlerand@Track(tracking might be for logging or monitoring purposes).Each method represents an operation exposed by the invoker:
findAllandfindByIduse theQueryGatewayto retrieve data through queries.save,update, anddeleteuse theCommandGatewayto send commands for creating, updating, and deleting data.
These methods delegate the actual work (fetching data or sending commands) to the respective gateways, providing a higher-level abstraction for external interaction.
Key Takeaways
the @Invokerhelps define classes that act as entry points for interacting with the RECQ architecture.Invokers provide a simplified interface, often mimicking a REST API, for external systems to interact with the application.
They leverage
CommandGatewayandQueryGatewayto orchestrate operations within the system.The
InvokerWrapperclass provides a foundation for implementing invokers with restricted gateway access and potential gateway retrieval logic.
By understanding @Invoker, you can effectively design facades that simplify interactions with your Evento applications, adhering to the principles of the RECQ architecture.
Last updated