manomano-tech / correlation-ids-httplug
该软件包已被弃用,不再维护。作者建议使用不再维护的软件包。
为 manomano-tech/correlation-ids 软件包提供的 HTTPlug 插件
1.0.0
2018-09-29 17:39 UTC
Requires
- php: ^7.1.3
- manomano-tech/correlation-ids: ^1.0
- php-http/client-common: ^1.0
- php-http/client-implementation: ^1.0
Requires (Dev)
- guzzlehttp/psr7: ^1.4.2
- php-http/mock-client: ^1.1.0
- phpunit/phpunit: ^7.3
- symfony/debug: ^4.1
- symfony/phpunit-bridge: ^4.1
This package is auto-updated.
Last update: 2022-07-18 15:14:09 UTC
README
📢 注意:此存储库不再维护。
HTTPlug 请求关联
在通过 httplug 发出的请求中注入关联头信息
安装
composer require manomano-tech/correlation-ids-httplug
使用方法
首先,生成一个 CorrelationIdContainer
use ManoManoTech\CorrelationId\Factory\CorrelationIdContainerFactory; use ManoManoTech\CorrelationId\Generator\RamseyUuidGenerator; // We specify which generator will be responsible for generating the // identification of the current process $generator = new RamseyUuidGenerator(); $factory = new CorrelationIdContainerFactory($generator); $correlationIdContainer = $factory->create( // can be any unique string '3fc044d9-90fa-4b50-b6d9-3423f567155f', // can be any unique string '3b5263fa-1644-4750-8f11-aaf61e58cd9e' );
然后,你有两个选择
将插件添加到你的 HTTPlug 客户端
use Http\Client\Common\PluginClient; use ManoManoTech\CorrelationIdHTTPlug\CorrelationIdHTTPlug; // create the middleware $requestIdPlugin = new CorrelationIdHTTPlug($correlationIdContainer); // $client = your client $pluginClient = new PluginClient($client, [$requestIdPlugin]);
使用工厂创建 HTTPlug 客户端
use ManoManoTech\CorrelationIdHTTPlug\HttpClientFactory; // create the middleware $factory = new HttpClientFactory($correlationIdContainer); // add some more plugins // $factory->addPlugin(...); // return an instance of Http\Client\Common\PluginClien $client = $factory->create();
自定义头名称
默认情况下,请求头将看起来像这样
GET / HTTP/1.1 Host: example.com parent-request-id: 3fc044d9-90fa-4b50-b6d9-3423f567155f root-request-id: 3b5263fa-1644-4750-8f11-aaf61e58cd9e
您可以通过向构造函数提供第二个参数来更改此设置
use Http\Client\Common\PluginClient; use ManoManoTech\CorrelationId\CorrelationEntryName; use ManoManoTech\CorrelationIdHTTPlug\CorrelationIdHTTPlug; // first argument is not used in this context $correlationEntryName = new CorrelationEntryName('current-id', 'parent-id', 'root-id'); $requestIdPlugin = new CorrelationIdHTTPlug($correlationIdContainer, $correlationEntryName); // $client = your client $pluginClient = new PluginClient($client, [$requestIdPlugin]);
或者,如果您使用工厂
use ManoManoTech\CorrelationId\CorrelationEntryName; use ManoManoTech\CorrelationIdHTTPlug\HttpClientFactory; // first argument is not used in this context $correlationEntryName = new CorrelationEntryName( 'current-id', // not used in this context 'parent-id', 'root-id' ); $factory = new HttpClientFactory($correlationIdContainer, $correlationEntryName); // add some more plugins // $factory->addPlugin(...); // return an instance of Http\Client\Common\PluginClien $client = $factory->create();
都将生成
GET / HTTP/1.1 Host: example.com parent-id: 3fc044d9-90fa-4b50-b6d9-3423f567155f root-id: 3b5263fa-1644-4750-8f11-aaf61e58cd9e