alexfn / nano-service
这是我打包的 nano-service
v1.7.4
2024-05-07 07:24 UTC
Requires
- php: ^8.1
- ext-curl: *
- league/statsd: ^2.0
- myclabs/php-enum: ^1.8
- php-amqplib/php-amqplib: ^3.5
- ramsey/uuid: ^3 || ^4
- spatie/crypto: ^2.0
Requires (Dev)
- phpunit/phpunit: ^9.6
- dev-main
- v1.7.4
- v1.7.3
- v1.7.2
- v1.7.1
- v1.7.0
- v1.6.31
- v1.6.30
- v1.6.29
- v1.6.28
- v1.6.27
- v1.6.26
- v1.6.25
- v1.6.24
- v1.6.23
- v1.6.22
- v1.6.21
- v1.6.20
- v1.6.19
- v1.6.18
- v1.6.17
- v1.6.16
- v1.6.15
- v1.6.14
- v1.6.12
- v1.6.11
- v1.6.10
- v1.6.9
- v1.6.8
- v1.6.7
- v1.6.6
- v1.6.5
- v1.6.4
- v1.6.3
- v1.6.2
- v1.6.1
- v1.6.0
- v1.5.1
- v1.5.0
- v1.4.0
- v1.2.0
- v1.1.1
- v1.1.0
- v1.0.0
- dev-dependabot/github_actions/dependabot/fetch-metadata-1.4.0
- dev-dependabot/github_actions/aglipanci/laravel-pint-action-2.2.0
This package is auto-updated.
Last update: 2024-09-07 08:12:58 UTC
README
这里应该放置你的描述。尽量限制在一两段话内。可以考虑添加一个小例子。
支持我们
我们投入了大量资源来创建一流的开放源代码包。你可以通过购买我们的付费产品之一来支持我们。
我们非常感谢你从家乡寄给我们明信片,并说明你正在使用我们哪个包。你可以在我们的联系页面上找到我们的地址。我们将所有收到的明信片发布在我们的虚拟明信片墙上。
安装
您可以通过 composer 安装此包
composer require alexfn/nano-service
使用
- 添加环境变量
AMQP_PROJECT="project-name" AMQP_HOST="rabbitmq-host" AMQP_PORT="5672" AMQP_USER="rmuser" AMQP_PASS="rmpassword" AMQP_VHOST="/" # Required for the consumer AMQP_MICROSERVICE_NAME="microservice-name" # For publisher encryption AMQP_PRIVATE_KEY="private-key" # For message getters AMQP_PUBLIC_KEY="public-key"
- 创建消息
$message = new NanoServiceMessage( // Body data [ 'key' => 'Value', ], // Message property (Optional) [ 'content_type' => 'text/json', 'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT, ] ); $message->addPayload([ 'key1' => 'Value 1', 'key2' => 'Value 2', ]);
- 发布消息
$message = (new NanoServiceMessage()) ->addPayload([ 'key' => 'Value', ]); (new NanoPublisher()) ->setMessage($message) ->publish('event-name');
- 消费消息
$consumer = new NanoConsumer(); $consumer ->events('event-one', 'event-two') ->consume(function (NanoServiceMessage $message) { $payload = $message->getPayload();// array });
其他消息方法
$message = (new NanoServiceMessage()) ->addPayload([ 'key' => 'Value', ]);
$message = (new NanoServiceMessage()) ->addMeta([ 'key' => 'Value', ]);
$message->getPayload(); $message->getPayloadAttribute('key'); $message->getPayloadAttribute('key', 'default_value'); $message->addPayload([]); $message->getPayloadAttribute('attribute', []); $message->getMeta(); $message->getMetaAttribute('key'); $message->getMetaAttribute('key', 'default_value'); $message->addMeta([]); $message->getMetaAttribute('attribute', []); $message->getStatusCode(); // Default 'unknown' $message->setStatusCode('success'); $message->getStatusData(); // Default [] $message->setStatusData([]);
使用私有/公开密钥加密数据
// Encrypting a message with a private key $message = (new NanoServiceMessage()) ->setEncryptedAttribute('attribute', 'My secret data');
// Decrypting with the public key $message->getEncryptedAttribute('attribute'); // My secret data
替换属性
$message = (new NanoServiceMessage()) ->addPayload([ 'key1' => 'Value 1', 'key2' => 'Value 2', ]) ->addPayload([ 'key1' => 'New value 1', 'key3' => 'New value 3', ]); // Result: {"key1":"Value 1","key2":"Value 2","key3":"New value 3"}
$message = (new NanoServiceMessage()) ->addPayload([ 'key1' => 'Value 1', 'key2' => 'Value 2', ]) ->addPayload( [ 'key1' => 'New value 1', 'key3' => 'New value 3', ], true ); // Result: {"key1":"New value 1","key2":"Value 2","key3":"New value 3"}
$message = (new NanoServiceMessage()) ->setStatusData([ 'key1' => 'Value 1', 'key2' => 'Value 2', ]) ->setStatusData( [ 'key1' => 'New value 1', 'key3' => 'New value 3', ], true ); // Result: {"key1":"New value 1","key3":"New value 3"}
调试模式
$message->setDebug();
(new NanoPublisher())
->setMessage($message)
->publish('event-name');
$consumer
->events('event-name')
->consume($callback, function (NanoServiceMessage $message) {
// debugCallback (Optional)
});
测试
composer test
变更日志
请参阅变更日志以获取有关最近更改的更多信息。
贡献
请参阅贡献指南以获取详细信息。
安全漏洞
请参阅我们的安全策略了解如何报告安全漏洞。
鸣谢
许可协议
MIT 许可协议 (MIT)。请参阅许可文件以获取更多信息。