aligent/async-bundle
Composer 安装命令:
composer require aligent/async-bundle
包简介
A bundle for extending Oro's Async processing
README 文档
README
This bundle provides:
-
An Abstract Processor class that will catch RetryableExceptions and after 3 (default) retries place the failed jobs into the database so they can be reviewed, fixed and then requeued.
-
Webhook integration
Installation Instructions
-
Install this module via Composer
composer require aligent/async-bundle -
Clear cache
php bin/console cache:clear -
Run Migrations
php bin/console oro:migration:load --force
Usage
Make sure your class extends the AbstractRetryableProcessor and perform your normal job processing in the execute function.
class TestJobProcessor extends AbstractRetryableProcessor
{
/**
* @param MessageInterface $message
* @return string
* @throws RetryableException
*/
public function execute(MessageInterface $message)
{
$body = JSON::decode($message->getBody());
try {
// Process the job here
$this->importSomeEntities($body);
} catch (\Exception $e) {
throw new RetryableException(
'This job failed and needs a retry',
0,
$e
);
}
}
}
By default the AbstractRetryableProcessor will fetch the passed exception from the RetryableException and store the trace. However if you aren't catching an exception you can just use the RetryableException and it will store the trace and message generated at this point.
class TestJobProcessor extends AbstractRetryableProcessor
{
/**
* @param MessageInterface $message
* @return string
* @throws RetryableException
*/
public function execute(MessageInterface $message)
{
$body = JSON::decode($message->getBody());
// Process the job here
$success = $this->importSomeEntities($body);
if (!$success) {
throw new RetryableException('This job failed and needs a retry');
}
}
}
You can also increase or decrease the amount of retries by overriding const MAX_RETRIES = 3; in your own class.
Set up Transport for Webhooks
Go to the "System -> Integrations -> Manage integrations" and click "Create Integration". Select "Webhook" as the integration type and fill all required fields.
To Enable set status as Active.
Once complete you must now receive webhook events to requested URL.
Dispatch webhook events
- EntityEventListener listens to any create/update/delete events; check if relevant webhook transport exists and active; if yes, pushes message to the queue
Aligent\AsyncEventsBundle\EventListener\EntityEventListener:
lazy: true
arguments:
- '@Aligent\AsyncEventsBundle\Provider\WebhookConfigProvider'
- '@oro_message_queue.client.message_producer'
- '@logger'
tags:
- { name: doctrine.event_listener, event: onFlush }
- { name: doctrine.event_listener, event: postFlush }
- WebhookEntityProcessor builds a payload and send a webhook event in response to the queued message.
Aligent\AsyncEventsBundle\Async\WebhookEntityProcessor:
parent: Aligent\AsyncEventsBundle\Async\AbstractRetryableProcessor
calls:
- [setConfigProvider, ['@Aligent\AsyncEventsBundle\Provider\WebhookConfigProvider']]
- [setTransport, ['@Aligent\AsyncEventsBundle\Integration\WebhookTransport']]
- [setSerializer, ['@oro_importexport.serializer']]
tags:
- { name: 'oro_message_queue.client.message_processor' }
- If you need to enrich payload data (ex., add addreses for the customer user), you can use OroImportExportBundle and add some custom normalizers to add/transform payload data.
Support
If you have any issues with this bundle, please create a GitHub issue.
Contribution
Any contribution is highly appreciated. The best way to contribute code is to open a pull request on GitHub.
Developer
Adam Hall adam.hall@aligent.com.au
Licence
aligent/async-bundle 适用场景与选型建议
aligent/async-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.31k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 11 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 aligent/async-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 aligent/async-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.31k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-11-21
