Evento Framework
  • Introduction
  • Architecture Overview
    • Distributed Systems & Microservices
    • Recative Manifesto & Reactive Principles
    • State-of-the-art Patterns
      • DDD (Domain Driven Design)
      • CQRS (Command Query Responsability Separation)
      • Event Sourcing
      • Messaging
      • Saga
  • GETTING STARTED
    • Quick Start
    • TodoList - RECQ Tutorial
      • Problem Description and Requirement Gathering
      • RECQ Payload Design
      • RECQ Components Design
      • Set up your Development Environment
      • RECQ Payload Evento Implementation
        • Domain Commands
        • Domain Events
        • Views
        • Queries
      • RECQ Components Evento Implementation with Spring Data
        • TodoListAggregate
        • TodoList Model with Spring Data
        • TodoListProjector
        • TodoListProjection
        • TodoList Invoker
      • Expose the RECQ architecture with Spring Web
      • Test Your App
    • Extend TodoList - Handle Complexity Tutorial
      • Unique identifier generation
      • Extends behaviors with Observer and Services
      • Cross Domain Consistency with Sagas
      • Handle Real time data updates with MQTT and Save-Notify Pattern
  • RECQ Patterns
    • RECQ Patterns
    • RECQ System Pattern
      • Component
      • Message Gateway
      • System State Store
    • RECQ Communication Pattern
      • Component to Component
      • Component to System State Store
      • System State Store to Component
    • RECQ Component Pattern
      • Aggregate
      • Projector
      • Projection
      • Service
      • Invoker
      • Saga
      • Observer
  • Evento Framework
    • Evento Framework Introcution
    • Payload and Messages
      • Command
        • Domain Command
        • Service Command
      • Event
        • Domain and Service Event
      • Query and View
    • @Component
      • @Aggregate
        • Aggregate State
        • @AggregateCommandHandler
        • @EventSourcingHandler
      • @Projector
        • Projector @EventHandler
      • @Projection
        • @QueryHandler
      • @Service
        • @CommandHandler
      • @Invoker
      • @Saga
        • SagaState
        • @SagaEventHandler
      • @Observer
    • Dead Event Queues
    • EventoBundle
      • EventoServerMessageBusConfiguration
      • ConsumerStateStore
        • InMemoryConsumerStateStore
        • PostgresConsumerStateStore
        • MysqlConsumerStateStore
      • Context
      • TracingAgend and @Track
        • SentryTracingAgent
      • Autoscaling Protocol
        • ThreadCountAutoscalingProtocol
      • Injector and @Component
  • Evento Server
    • Evento Server Introduction
    • SetUp Evento Server
      • Advanced Options
      • Evento Event Store Modes: APES and CPES
    • Evento Server Cluster
    • Bundle Deploy Script
  • EVENTO GUI
    • Explore RECQ Systems Visually
    • GUI Auth
    • Payload Catalog
    • Component Catalog
    • Bundle Catalog
    • Cluster Status (Experimental)
    • Flows
      • Performance Evaluation
    • Application Graph
    • System State Store
  • Evento CLI
    • Evento CLI Introduction
    • Update Version
    • Publish
Powered by GitBook
On this page
  1. Evento Framework
  2. EventoBundle
  3. ConsumerStateStore

MysqlConsumerStateStore

The MysqlConsumerStateStore class in the Evento Framework extends ConsumerStateStore and provides a solution for storing and managing consumer state information within a MySQL database. This chapter explores the functionalities and usage of MysqlConsumerStateStore for persistent state handling in Evento applications.

MySQL Storage:

  • Leverages MySQL, a popular open-source relational database management system, to store consumer state data.

  • Offers a familiar and widely adopted alternative to PostgreSQL for persistent state management.

  • Ensures that saga state and consumer progress are preserved across application restarts.

Key Methods:

  • Constructors:

    • Similar to PostgresConsumerStateStore, the primary constructor accepts an EventoServer instance, a PerformanceService instance, a Connection object for connecting to the MySQL database, an ObjectMapper for serialization/deserialization, and an Executor for handling observer execution concurrently.

  • init(): This method is crucial and should be called once before using the consumer state store. It executes Data Definition Language (DDL) statements to create the necessary tables (evento__consumer_state and evento__saga_state) within the MySQL database if they don't already exist.

  • removeSagaState(Long sagaId): Deletes the state associated with a specific saga identified by its ID.

  • leaveExclusiveZone(String consumerId): Releases the lock on the consumer, signifying it has exited the exclusive zone.

  • enterExclusiveZone(String consumerId): Attempts to acquire a lock for the consumer using MySQL's GET_LOCK function. This ensures exclusive access to the consumer's state during processing.

  • getLastEventSequenceNumber(String consumerId): Retrieves the last processed event sequence number for a consumer from the evento__consumer_state table.

  • setLastEventSequenceNumber(String consumerId, Long eventSequenceNumber): Updates the last processed event sequence number for a consumer in the evento__consumer_state table.

  • getSagaState(String sagaName, String associationProperty, String associationValue): Retrieves the stored state for a saga identified by its name, association property, and association value. It utilizes a JSON path query within the MySQL database to efficiently locate the relevant saga state.

  • setSagaState(Long id, String sagaName, SagaState sagaState): Sets the state for a saga. If an ID is provided (indicating an existing saga), it updates the state for that specific saga. Otherwise, it inserts a new entry for the saga into the evento__saga_state table.

Usage Example:

The provided code snippet demonstrates how to configure MysqlConsumerStateStore within an Evento application using a lambda expression within the setConsumerStateStoreBuilder method:

EventoBundle.Builder.builder()
    .setBasePackage(DemoSagaApplication.class.getPackage())
    .setConsumerStateStoreBuilder(((eventoServer, performanceService) -> {
        return new MysqlConsumerStateStore(
                eventoServer,
                performanceService,
                connection); // Connection Object
    }))
    ...
    .start();

In this example, a Connection object (representing the connection to the MySQL database) is provided during the consumer state store creation.

Important Considerations:

  • MysqlConsumerStateStore relies on a MySQL database for storage. Ensure you have a properly configured MySQL instance accessible to your Evento application.

  • Remember to call the init() method to create the necessary tables before using the consumer state store.

  • MySQL offers a strong foundation for persistent state management, with a rich ecosystem of tools and libraries.

By choosing MysqlConsumerStateStore, you can leverage the familiarity and widespread adoption of MySQL for persistent state management within your Evento applications. This ensures data integrity and reliability across application restarts.

PreviousPostgresConsumerStateStoreNextContext

Last updated 12 months ago