{"id":23219127,"url":"https://github.com/b2pweb/bdf-prime-events","last_synced_at":"2025-04-05T14:42:45.443Z","repository":{"id":41822485,"uuid":"381988514","full_name":"b2pweb/bdf-prime-events","owner":"b2pweb","description":"Prime library for listen MySQL events from replication protocol","archived":false,"fork":false,"pushed_at":"2024-02-28T14:40:17.000Z","size":56,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"2.0","last_synced_at":"2025-03-14T02:04:10.140Z","etag":null,"topics":["mysql-events","mysql-replication-listener"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/b2pweb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-07-01T10:02:16.000Z","updated_at":"2021-12-17T10:16:34.000Z","dependencies_parsed_at":"2024-02-28T15:29:47.133Z","dependency_job_id":"79d953dc-16bb-4b45-be0b-6131770b7850","html_url":"https://github.com/b2pweb/bdf-prime-events","commit_stats":{"total_commits":53,"total_committers":2,"mean_commits":26.5,"dds":"0.018867924528301883","last_synced_commit":"f6b34d380b9445c1317fc7fee3c3e51904cd15c8"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b2pweb%2Fbdf-prime-events","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b2pweb%2Fbdf-prime-events/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b2pweb%2Fbdf-prime-events/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b2pweb%2Fbdf-prime-events/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/b2pweb","download_url":"https://codeload.github.com/b2pweb/bdf-prime-events/tar.gz/refs/heads/2.0","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247353681,"owners_count":20925325,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mysql-events","mysql-replication-listener"],"created_at":"2024-12-18T21:19:22.142Z","updated_at":"2025-04-05T14:42:45.421Z","avatar_url":"https://github.com/b2pweb.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Prime Events\n[![build](https://github.com/b2pweb/bdf-prime-events/actions/workflows/php.yml/badge.svg)](https://github.com/b2pweb/bdf-prime-events/actions/workflows/php.yml)\n[![codecov](https://codecov.io/github/b2pweb/bdf-prime-events/branch/2.0/graph/badge.svg?token=VOFSPEWYKX)](https://app.codecov.io/github/b2pweb/bdf-prime-events)\n[![Packagist Version](https://img.shields.io/packagist/v/b2pweb/bdf-prime-events.svg)](https://packagist.org/packages/b2pweb/bdf-prime-events)\n[![Total Downloads](https://img.shields.io/packagist/dt/b2pweb/bdf-prime-events.svg)](https://packagist.org/packages/b2pweb/bdf-prime-events)\n[![Type Coverage](https://shepherd.dev/github/b2pweb/bdf-prime-events/coverage.svg)](https://shepherd.dev/github/b2pweb/bdf-prime-events)\n\nPrime extension for listen MySQL replication events on Prime entities to track insert, update and delete operations.\n\n## Installation\n\nInstall with composer :\n\n```bash\ncomposer require b2pweb/bdf-prime-events\n```\n\n### Configuration on Symfony\n\nRegister into `config/bundles.php` :\n\n```php\n\u003c?php\n\nreturn [\n    // ...\n    Bdf\\PrimeEvents\\Bundle\\PrimeEventsBundle::class =\u003e ['all' =\u003e true],\n    Bdf\\PrimeBundle\\PrimeBundle::class =\u003e ['all' =\u003e true],\n];\n```\n\nConfigure indexes into `config/packages/prime_events.yaml` :\n\n```yaml\nprime_events:\n  # Configure replication connection parameter here, by connection name\n  my_connection:\n    user: other_user # Define a custom username/password which as REPLICATION CLIENT and REPLICATION SLAVE permissions\n    password: other_pass\n    logPositionFile: '%kernel.project_dir%/var/events' # The file for store the last consumed event, to allow restart consumer without loose events \n\n```\n\nEnable autoconfigure on application to let Symfony container configure the listeners :\n\n```yaml\nservices:\n  _defaults:\n    autowire: true\n    autoconfigure: true\n\n  App\\Entity\\Listener\\:\n    resource: './src/Entity/Listener'\n\n```\n\n### Configure MySQL\n\nSee [krowinski/php-mysql-replication](https://github.com/krowinski/php-mysql-replication#mysql-server-settings) for enable replication protocol on the MySQL server.\n\n## Usage\n\nPrime entities are use for events, see [Create your mapper](https://github.com/b2pweb/bdf-prime#create-your-mapper) to define an entity.\n\n### Simple usage / without Symfony\n\nSimply create an `EntityEventsConsumer`, define listeners, and run the consumer :\n\n```php\nuse Bdf\\PrimeEvents\\EntityEventsConsumer;\nuse MySQLReplication\\Config\\ConfigBuilder;\n\n$consumer = new EntityEventsConsumer(\n    $prime, // The ServiceLocator instance\n    __DIR__.'/mysql_last_event.log', // File for store the last consumed event, to allow restart without loosing events\n    function (ConfigBuilder $config) {\n        $config\n            // Define custom connection configuration\n            // Note: by default, the connection user and password is used\n            // So it's not required to redefine it if the user has the replication permissions\n            -\u003ewithUser('replication_user')\n            -\u003ewithPassword('replication_pass')\n            // Define the slave id. define this value is required if you want to run multiple\n            // consumers on the same database\n            -\u003ewithSlaveId(123) \n        ;\n    }\n);\n\n// Configure listener for MyEntity\n$consumer-\u003eforEntity(MyEntity::class)\n    -\u003einserted(function (MyEntity $entity) { /* $entity has been inserted */})\n    -\u003eupdated(function (MyEntity $before, MyEntity $now) { /* The entity has been updated. $before is its value before the update, and $now the current value */ })\n    -\u003edeleted(function (MyEntity $entity) { /* $entity has been deleted */})\n;\n\n// Other entities may be configure...\n\n// Consume all events\n// Note: consume() will only consume 1 event\nwhile ($running) {\n    $consumer-\u003econsume();\n}\n\n// Stop the consumer and save the last consumed events\n$consumer-\u003estop();\n```\n\n### Usage with Symfony\n\nSymfony will autoconfigure the listeners if there implements `EntityEventsListenerInterface` :\n\n```php\nuse Bdf\\PrimeEvents\\Factory\\EntityEventsListenerInterface;\n\n/**\n * @implements EntityEventsListenerInterface\u003cMyEntity\u003e\n */\nclass MyEntityListeners implements EntityEventsListenerInterface\n{\n    /**\n     * {@inheritdoc}\n     */\n    public function entityClass() : string\n    {\n        return MyEntity::class;\n    }\n\n    /**\n     * {@inheritdoc} \n     * @param MyEntity $entity\n     */\n    public function onInsert($entity) : void\n    {\n        // $entity has been inserted\n    }\n    \n    /**\n     * {@inheritdoc} \n     * @param MyEntity $oldEntity\n     * @param MyEntity $newEntity\n     */\n    public function onUpdate($oldEntity, $newEntity) : void\n    {\n        // The entity has been updated.\n        // $before is its value before the update, and $now the current value\n    }\n    \n    /**\n     * {@inheritdoc} \n     * @param MyEntity $entity\n     */\n    public function onDelete($entity) : void\n    {\n        // $entity has been deleted\n    }  \n}\n```\n\nTo consume events, simply launch `prime:events:consume` command :\n\n```\nbin/console prime:events:consume my_connection --limit 10000 --memory 500m\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fb2pweb%2Fbdf-prime-events","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fb2pweb%2Fbdf-prime-events","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fb2pweb%2Fbdf-prime-events/lists"}