yousign/zdd-message-bundle
Composer 安装命令:
composer require --dev yousign/zdd-message-bundle
包简介
Assert Zero Downtime Deployment compliance for messages
README 文档
README
A Symfony Bundle to use when you want to assert that messages used with Message brokers such like RabbitMQ are compliant with the Zero Downtime Deployment.
Getting started
Installation
First, install the bundle with composer:
$ composer require yousign/zdd-message-bundle
Then, verify that the bundle has been registered in config/bundles.php:
Yousign\ZddMessageBundle\ZddMessageBundle::class => ['all' => true],
Configuration
Create a class to configure the messages to assert and how to create them:
<?php namespace App\Message; use Yousign\ZddMessageBundle\Config\CustomMessageGeneratorInterface; use Yousign\ZddMessageBundle\Config\ZddMessageConfigInterface; class MessageConfig implements ZddMessageConfigInterface, CustomMessageGeneratorInterface { /** * Return the list of messages to assert. */ #[\Override] public function getMessageToAssert(): array { return [ App\Message\MyMessage::class, App\Message\AnotherMessage::class, //... ]; } /** * If your message contains no scalar value as parameter such like value enums, value object more complex object, * you should use this method to return value for each type hint. */ #[\Override] public function generateValueForCustomPropertyType(string $type): mixed { return match ($type) { 'App\ValueObject\Email' => new App\ValueObject\Email('dummy@email.fr'), 'App\Enum\MyEnum' => App\Enum\MyEnum::MY_VALUE, default => null, }; } /** * Optional: Implement CustomMessageGeneratorInterface if you need full control * over how a specific message instance is created. * This is useful when the default instantiation (using reflection and property injection) * is not sufficient or when your message requires specific constructor logic. * * WARNING: The object must be instantiated with minimum requirements (i.e., nullable properties * must be set as null) in order to ensure a good ZDD test. */ #[\Override] public function generateCustomMessage(string $className): ?object { return match ($className) { App\Message\ComplexMessage::class => new App\Message\ComplexMessage('custom data'), default => null, }; } }
Then, register this class as a service.
# config/services.yaml App\Message\MessageConfig:
Finish by updating the configuration with this new service in config/packages/zdd_message.yaml:
# config/packages/zdd_message.yaml zdd_message: message_config_service: App\Message\MessageConfig
Optional configuration
Use a custom serializer
Option to use different serializer. Possible options:
Yousign\ZddMessageBundle\Serializer\ZddMessageMessengerSerializer(default, already configured for messenger serialization in messenger.yaml)- Define your own serializer
- Create a service that implement
Yousign\ZddMessageBundle\Serializer\SerializerInterface - Use it in the configuration
- Create a service that implement
# config/packages/zdd_message.yaml zdd_message: serializer: '<your-service-id>'
Custom directory for serialized messages
Option to specify a custom directory where serialized messages will be stored.
# config/packages/zdd_message.yaml zdd_message: # ... serialized_messages_dir: '%kernel.project_dir%/custom/path' # Default: '%kernel.project_dir%/var/zdd-message'
Detect messages not tracked
Option to write a log message if an asynchronous message has been sent (using symfony messenger) and is not present in your configuration.
# config/packages/zdd_message.yaml zdd_message: # ... log_untracked_messages: messenger: enable: true # false by default level: 'error' # warning by default
Usage
The bundle comes with commands to assert that your messages are compliant with the Zero Downtime Deployment:
$ bin/console yousign:zdd-message:generate # Generate serialized messages in files. $ bin/console yousign:zdd-message:validate # Assert that the messages are compliant by deserializing them from files and call the properties. $ bin/console yousign:zdd-message:debug # Output all tracked messages.
💡 You should run bin/console yousign:zdd-message:generate with the production version code and bin/console yousign:zdd-message:validate with the version code you want to merge.
Example from the version you want to merge:
$ git checkout [production_version]
$ bin/console yousign:zdd-message:generate
$ git checkout - # Go back to the version you want to merge
$ bin/console yousign:zdd-message:validate
💡 Use verbose mode to see error details
$ bin/console yousign:zdd-message:validate -vv
--- ------------------------------------------------------------------- ----------------
# Message ZDD Compliant?
--- ------------------------------------------------------------------- ----------------
1 Yousign\ZddMessageBundle\Tests\Fixtures\App\Messages\DummyMessage No ❌
--- ------------------------------------------------------------------- ----------------
! [NOTE] 1 error(s) triggered.
------------------------------------------------------------------- --------------
Message Error
------------------------------------------------------------------- --------------
Yousign\ZddMessageBundle\Tests\Fixtures\App\Messages\DummyMessage Syntax error
------------------------------------------------------------------- --------------
Contributing
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
After writing your fix/feature, you can run following commands to make sure that everything is still ok.
# Install dev dependencies $ composer install # Running tests and quality tools locally $ make all
If you want to use your local fork to develop in your projects, you can use the link command to replace the vendor installation by your local version.
$ ./link /home/yousign/dev/my-project
Authors
- Smaine Milianni - ismail1432 - <smaine(dot)milianni@gmail(dot)com>
- Simon Mutricy - Inkod - <ink0d@pm(dot)me>
yousign/zdd-message-bundle 适用场景与选型建议
yousign/zdd-message-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 127.77k 次下载、GitHub Stars 达 27, 最近一次更新时间为 2023 年 05 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「dev」 「zdd」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 yousign/zdd-message-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yousign/zdd-message-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 yousign/zdd-message-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Monolog bridge for PHP Debugbar
Simple and fast methods to read private properties and call private methods
Analysis module for finding problematical shop data.
Analysis module for finding problematical shop data.
Enforce architecture by defining modules with allowed dependencies. Detects forbidden, uncovered, missing and unused module dependencies in PHP projects.
Analysis module for finding problematical shop data.
统计信息
- 总下载量: 127.77k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 28
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-05-24