3slab/vdm-library-http-transport-bundle
Composer 安装命令:
composer require 3slab/vdm-library-http-transport-bundle
包简介
Vdm Http Transport
README 文档
README
This symfony messenger extension provides a transport to pull data from a HTTP source.
Installation
composer require 3slab/vdm-library-http-transport-bundle
Configuration reference
framework:
messenger:
transports:
consumer:
dsn: "http://ipconfig.io/json"
retry_strategy:
max_retries: 0
options:
method: GET
http_options: {}
http_executor: ~
monitoring:
enabled: true
retry:
enabled: true
number: 5
timeBeforeRetry: 5
| Configuration | Description |
|---|---|
| dsn | the url you want to collect (needs to start by http or https) |
| retry_strategy.max_retries | needs to be 0 because http transport does not support this feature |
| options.method | HTTP method to be called |
| options.http_options | options supported on request by the symfony http client |
| options.http_executor | set the id (in the container of services) of a custom http executor to use instead of the DefaultHttpExecutor |
| options.monitoring.enabled | if true, hook up in the vdm library bundle monitoring system to send information about the HTTP response |
| options.retry.enabled | if true, retry an http call in case of error |
| options.retry.number | number of time to retry before stopping with error |
| options.retry.timeBeforeRetry | time in second between each try (multiplied by the current retry number to delay) |
HTTP Executor
HTTP executor allows you to customize the behavior of the HTTP transport per transport definition inside your messenger.yaml file.
Some example use cases are that the API has a pagination or needs a pre-request for authentication.
If you don't set a custom http_executor option when declaring the transport, the default DefaultHttpExecutor is used
which just calls the API using the default Symfony http client with the method and http_options you have configured.
You can override this behavior in your project by providing a class that extends Vdm\Bundle\LibraryBundle\Executor\Http\AbstractHttpExecutor.
namespace App\Executor\Http;
use Psr\Log\LoggerInterface;
use Symfony\Component\Messenger\Envelope;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Vdm\Bundle\LibraryBundle\Model\Message;
use Vdm\Bundle\LibraryBundle\Stamp\StopAfterHandleStamp;
class CustomHttpExecutor extends AbstractHttpExecutor
{
public function __construct(
HttpClientInterface $httpClient,
LoggerInterface $vdmLogger = null
) {
parent::__construct($httpClient, $vdmLogger);
}
public function execute(string $dsn, string $method, array $options): iterable
{
// In HttpClient, request just build the request but does not execute it
$response = $this->httpClient->request($method, $dsn, $options);
$message = new HttpMessage($response->getContent());
yield new Envelope($message, [new StopAfterHandleStamp()]);
}
}
There are 2 important things your custom executor needs to do :
yielda new envelope- Add a
StopAfterHandleStampstamp to the yielded envelope if you want to stop after handling the last message (if not, the messenger worker may loop over and will execute it once again without stopping)
Note : thanks to the yield system, you can implement a loop in your execute function and return items once at a time
Note : you can keep state in your custom executor so if it is executed again, adapt your API call
Then references this custom executor in your transport definition in your project messenger.yaml :
framework:
messenger:
transports:
api-call:
options:
http_executor: App\Executor\Http\CustomHttpExecutor
Monitoring
If you enable monitoring, it will track the following metrics :
- Counter on the HTTP response status code
- Size of the HTTP response body
- The HTTP response time
3slab/vdm-library-http-transport-bundle 适用场景与选型建议
3slab/vdm-library-http-transport-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.35k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 04 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 3slab/vdm-library-http-transport-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 3slab/vdm-library-http-transport-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.35k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 1
其他信息
- 授权协议: proprietary
- 更新时间: 2020-04-29