umbrellio / php-table-sync
PHP's implementation of the library providing data synchronization between microservices
Installs: 39 180
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 4
Forks: 0
Open Issues: 2
Requires
- php: ^8.1
- ext-json: *
- ext-posix: *
- influxdb/influxdb-php: ^1.15
- laravel/framework: ^10.0
- monolog/monolog: ^3.0
- php-amqplib/php-amqplib: ^3.0
- thecodingmachine/safe: ^2.0
- umbrellio/laravel-heavy-jobs: ^3.0
Requires (Dev)
- laravel/legacy-factories: *
- mikey179/vfsstream: ^1.6
- mockery/mockery: ^1.0
- orchestra/testbench: ^8.0
- php-coveralls/php-coveralls: ^2.1
- php-mock/php-mock: ^2.0
- phpunit/phpunit: ^10.0
- squizlabs/php_codesniffer: ^3.5
- symplify/easy-coding-standard: ^11.0
README
PHP's implementation of the library providing data synchronization between microservices
Installation
composer require umbrellio/php-table-sync php artisan vendor:publish --tag=config-table-sync
Usage
Let's describe the model that needs to be synchronized using an example User.php
... User extends Model implements SyncableModel { use TableSyncable; ... public function routingKey(): string { return 'users'; } public function getTableSyncableAttributes(): array { return [ 'id' => $this->external_id, 'login' => $this->name, 'email' => $this->email, ]; } ...
When the model changes, the data will be sent according to the rules of TableSyncObserver
, to get the data you need to run the command table_sync:work
Logging
Logging based on the Monolog package and contains some extensions for it.
- specify the logging channel in
config/table_sync.php
... 'log' => [ 'channel' => 'table_sync', ], ...
- and describe this channel in
config/logging.php
... 'table_sync' => [ 'driver' => 'stack', 'channels' => ['table_sync_daily', 'influxdb'], ], 'table_sync_daily' => [ 'driver' => 'daily', 'formatter' => LineTableSyncFormatter::class, 'formatter_with' => [ 'format' => '[%datetime%] %message% - %model% %event%', ], 'path' => storage_path('logs/table_sync/daily.log'), ], 'influxdb' => [ 'driver' => 'influxdb', 'measurement' => 'table_sync', ], ...
You can use the built-in LineTableSyncFormatter::class
with the available parameters: %datetime%
%message%
%direction%
%model%
%event%
%routing%
%attributes%
%exception%
Driver influxdb
is an additional option and is not required to add in config
... 'table_sync' => [ 'driver' => 'daily', ], ...
Authors
Created by Korben Dallas.