google /
PHP 的 Cloud Pub/Sub 客户端
Requires
- php: ^8.0
- google/cloud-core: ^1.55
- google/gax: ^1.34.0
Requires (Dev)
- erusev/parsedown: ^1.6
- flix-tech/avro-php: ^5.0.0
- phpdocumentor/reflection: ^5.3.3
- phpdocumentor/reflection-docblock: ^5.3
- phpspec/prophecy-phpunit: ^2.0
- phpunit/phpunit: ^9.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.
- dev-main
- v2.5.2
- v2.5.1
- v2.5.0
- v2.4.0
- v2.3.0
- v2.2.1
- v2.2.0
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.0
- v2.0.0-RC1
- v1.51.0
- v1.50.0
- v1.49.0
- v1.48.0
- v1.47.0
- v1.46.4
- v1.46.3
- v1.46.2
- v1.46.1
- v1.46.0
- v1.45.2
- v1.45.1
- v1.45.0
- v1.44.0
- v1.43.2
- v1.43.1
- v1.43.0
- v1.42.1
- v1.42.0
- v1.41.3
- v1.41.2
- v1.41.1
- v1.41.0
- v1.40.1
- v1.40.0
- v1.39.3
- v1.39.2
- v1.39.1
- v1.39.0
- v1.38.4
- v1.38.3
- v1.38.2
- v1.38.1
- v1.38.0
- v1.37.0
- v1.36.1
- v1.36.0
- v1.35.1
- v1.35.0
- v1.34.3
- v1.34.2
- v1.34.1
- v1.34.0
- v1.33.0
- v1.32.0
- v1.31.1
- v1.31.0
- v1.30.3
- v1.30.2
- v1.30.1
- v1.30.0
- v1.29.4
- v1.29.3
- v1.29.2
- v1.29.1
- v1.29.0
- v1.28.0
- v1.27.0
- v1.26.0
- v1.25.0
- v1.24.1
- v1.24.0
- v1.23.0
- v1.22.0
- v1.21.1
- v1.21.0
- v1.20.0
- v1.19.0
- v1.18.0
- v1.17.0
- v1.16.0
- v1.15.0
- v1.14.0
- v1.13.0
- v1.12.2
- v1.12.1
- v1.12.0
- v1.11.2
- v1.11.1
- v1.11.0
- v1.10.0
- v1.9.0
- v1.8.2
- v1.8.1
- v1.8.0
- v1.7.2
- v1.7.1
- v1.7.0
- v1.6.0
- v1.5.1
- v1.5.0
- v1.4.4
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.2
- v1.0.1
- v1.0.0
- v0.12.2
- v0.12.1
- v0.12.0
- v0.11.3
- v0.11.2
- v0.11.1
- v0.11.0
- v0.10.0
- v0.9.2
- v0.9.1
- v0.9.0
- v0.8.0
- v0.7.0
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.1
- v0.5.0
- v0.4.0
- v0.3.0
- v0.2.0
- v0.1.0
This package is auto-updated.
Last update: 2024-09-13 22:49:35 UTC
README
云 Pub/Sub 的 PHP 风格客户端。
注意: 此存储库是 Google Cloud PHP 的一个部分。[https://github.com/googleapis/google-cloud-php](https://github.com/googleapis/google-cloud-php)。任何支持请求、错误报告或开发贡献都应指向该项目。
一个完全托管的实时消息服务,允许您在独立应用程序之间发送和接收消息。
安装
首先,安装 PHP 偏好的依赖项管理器 [Composer](https://getcomposer.org.cn/)。
现在安装此组件
$ composer require google/cloud-pubsub
此组件支持通过 HTTP/1.1 的 REST 和 gRPC。为了利用 gRPC 提供的好处(如流式方法),请参阅我们的 [gRPC 安装指南](https://cloud.google.com/php/grpc)。
身份验证
有关客户端身份验证的更多信息,请参阅我们的 [身份验证指南](https://github.com/googleapis/google-cloud-php/blob/main/AUTHENTICATION.md)。一旦身份验证,您就可以开始进行请求。
示例
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(通用可用)。因此,它不会在任何次要或补丁版本中引入不兼容的更改。我们将以最高优先级解决问题和请求。
请参阅 [迁移指南](https://github.com/googleapis/google-cloud-php-pubsub/blob/HEAD/./MIGRATING.md),了解如何从库的 V1 迁移到 V2。
下一步
- 了解 [官方文档](https://cloud.google.com/pubsub/docs/)。
- 查看 [深入使用示例](https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/pubsub/)。