triwinvendor / google-pubsub
PHP的Cloud Pub/Sub客户端
1.0.0
2022-10-13 07:01 UTC
Requires
- google/cloud-core: ^1.39
- google/gax: ^1.1
Requires (Dev)
- erusev/parsedown: ^1.6
- phpdocumentor/reflection: ^3.0
- phpunit/phpunit: ^4.8|^5.0
- squizlabs/php_codesniffer: 2.*
Suggests
- ext-grpc: The gRPC extension enables use of the performant gRPC transport
- ext-protobuf: Provides a significant increase in throughput over the pure PHP protobuf implementation. See https://cloud.google.com/php/grpc for installation instructions.
This package is not auto-updated.
Last update: 2024-09-27 14:19:17 UTC
README
这是一个用于Cloud Pub/Sub的PHP的惯用客户端。
注意:该仓库是Google Cloud PHP的一部分。任何支持请求、错误报告或开发贡献都应指向该项目。
这是一个全托管的实时消息服务,允许您在独立应用程序之间发送和接收消息。
安装
首先,安装PHP的首选依赖管理器Composer。
现在只安装此组件
$ composer require google/cloud-pubsub
或者一次性安装整个组件集
$ composer require google/cloud
此组件支持HTTP/1.1上的REST和gRPC。要利用gRPC(如流方法)提供的优势,请参阅我们的gRPC安装指南。
身份验证
请参阅我们的身份验证指南以了解更多关于身份验证客户端的信息。身份验证后,您即可开始发送请求。
示例
require 'vendor/autoload.php'; use Google\Cloud\PubSub\PubSubClient; $pubSub = new PubSubClient(); // Get an instance of a previously created topic. $topic = $pubSub->topic('my_topic'); // Publish a message to the topic. $topic->publish([ 'data' => 'My new message.', 'attributes' => [ 'location' => 'Detroit' ] ]); // Get an instance of a previously created subscription. $subscription = $pubSub->subscription('my_subscription'); // Pull all available messages. $messages = $subscription->pull(); foreach ($messages as $message) { echo $message->data() . "\n"; echo $message->attribute('location'); }
版本
此组件被认为是GA(一般可用)。因此,它不会在任何次要或补丁版本中引入向后不兼容的更改。我们将优先解决问题和请求。