googleapis/google-cloud-php

Not able to use the PubSub Emulator

local-l opened this issue · 2 comments

The PubSub client tries to connect with https to the locally running PubSub Emulator which only supports http.

Environment details

  • OS: Debian GNU/Linux 12 (bookworm)
  • PHP version: PHP 8.3.11 (cli) (built: Sep 4 2024 23:56:45) (NTS)
  • Package name and version: google/cloud-pubsub 2.5.2

Steps to reproduce

  1. Install and start the PubSub Emulator according to https://cloud.google.com/pubsub/docs/emulator e.g. as a container:

    podman run --publish 127.0.0.1:8085:8085 \
      gcr.io/google.com/cloudsdktool/google-cloud-cli:emulators \
      gcloud beta emulators pubsub start --project=my-project
    
  2. Verify container is reachable:

    curl http://localhost:8085
    Ok
    
  3. Configure environment

    export PUBSUB_EMULATOR_HOST=localhost:8085
    export PUBSUB_PROJECT_ID=my-project
    curl -sL -o example-key.json https://github.com/googleapis/google-cloud-php/raw/main/.github/emulator/example-key.json
    export GOOGLE_APPLICATION_CREDENTIALS=example-key.json
    

Code example

require 'vendor/autoload.php';

use Google\Cloud\PubSub\PubSubClient;

$pubSub = new PubSubClient();

$topic = $pubSub->createTopic('my_topic');

Expected result

Topic is created

Actual result

Client tries to connect with https and fails:

Fatal error: Uncaught GuzzleHttp\Exception\ConnectException: cURL error 35: OpenSSL/3.0.14: error:0A00010B:SSL routines::wrong version number (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://localhost:8085/v1/projects/emulator-project/topics/my_topic?%24alt=json%3Benum-encoding%3Dint in /vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:275
Stack trace:
#0 /vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(205): GuzzleHttp\Handler\CurlFactory::createRejection(Object(GuzzleHttp\Handler\EasyHandle), Array)
#1 /vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(157): GuzzleHttp\Handler\CurlFactory::finishError(Object(GuzzleHttp\Handler\CurlMultiHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory))
#2 /vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(267): GuzzleHttp\Handler\CurlFactory::finish(Object(GuzzleHttp\Handler\CurlMultiHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory))
#3 /vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(180): GuzzleHttp\Handler\CurlMultiHandler->processMessages()
#4 /vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(206): GuzzleHttp\Handler\CurlMultiHandler->tick()
#5 /vendor/guzzlehttp/promises/src/Promise.php(251): GuzzleHttp\Handler\CurlMultiHandler->execute(true)
#6 /vendor/guzzlehttp/promises/src/Promise.php(227): GuzzleHttp\Promise\Promise->invokeWaitFn()
#7 /vendor/guzzlehttp/promises/src/Promise.php(272): GuzzleHttp\Promise\Promise->waitIfPending()
#8 /vendor/guzzlehttp/promises/src/Promise.php(229): GuzzleHttp\Promise\Promise->invokeWaitList()
#9 /vendor/guzzlehttp/promises/src/Promise.php(69): GuzzleHttp\Promise\Promise->waitIfPending()
#10 /vendor/google/cloud-pubsub/src/V1/Client/PublisherClient.php(346): GuzzleHttp\Promise\Promise->wait()
#11 [internal function]: Google\Cloud\PubSub\V1\Client\PublisherClient->createTopic(Object(Google\Cloud\PubSub\V1\Topic), Array)
#12 /vendor/google/cloud-core/src/RequestHandler.php(118): call_user_func_array(Array, Array)
#13 /vendor/google/cloud-pubsub/src/Topic.php(252): Google\Cloud\Core\RequestHandler->sendRequest('Google\\Cloud\\Pu...', 'createTopic', Object(Google\Cloud\PubSub\V1\Topic), Array)
#14 /vendor/google/cloud-pubsub/src/PubSubClient.php(256): Google\Cloud\PubSub\Topic->create(Array)
#15 /test.php(8): Google\Cloud\PubSub\PubSubClient->createTopic('my_topic')

Composer Versions

brick/math                    0.12.1 Arbitrary-precision arithmetic library
firebase/php-jwt              6.10.1 A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to...
google/auth                   1.42.0 Google Auth Library for PHP
google/cloud-core             1.59.1 Google Cloud PHP shared dependency, providing functionality useful to all components.
google/cloud-pubsub           2.5.2  Cloud PubSub Client for PHP
google/common-protos          4.8.3  Google API Common Protos for PHP
google/gax                    1.34.1 Google API Core for PHP
google/grpc-gcp               0.4.0  gRPC GCP library for channel management
google/longrunning            0.4.3  Google LongRunning Client for PHP
google/protobuf               4.28.1 proto library for PHP
grpc/grpc                     1.57.0 gRPC library for PHP
guzzlehttp/guzzle             7.9.2  Guzzle is a PHP HTTP client library
guzzlehttp/promises           2.0.3  Guzzle promises library
guzzlehttp/psr7               2.7.0  PSR-7 message implementation that also provides common utility methods
monolog/monolog               3.7.0  Sends your logs to files, sockets, inboxes, databases and various web services
psr/cache                     3.0.0  Common interface for caching libraries
psr/http-client               1.0.3  Common interface for HTTP clients
psr/http-factory              1.1.0  PSR-17: Common interfaces for PSR-7 HTTP message factories
psr/http-message              2.0    Common interface for HTTP messages
psr/log                       3.0.2  Common interface for logging libraries
ralouphie/getallheaders       3.0.3  A polyfill for getallheaders.
ramsey/collection             2.0.0  A PHP library for representing and manipulating collections.
ramsey/uuid                   4.7.6  A PHP library for generating and working with universally unique identifiers (UUIDs).
rize/uri-template             0.3.8  PHP URI Template (RFC 6570) supports both expansion & extraction
google/cloud-core             1.59.1 Google Cloud PHP shared dependency, providing functionality useful to all components.
google/cloud-pubsub           2.5.2  Cloud PubSub Client for PHP
google/common-protos          4.8.3  Google API Common Protos for PHP
google/gax                    1.34.1 Google API Core for PHP
google/grpc-gcp               0.4.0  gRPC GCP library for channel management
google/longrunning            0.4.3  Google LongRunning Client for PHP
google/protobuf               4.28.1 proto library for PHP
grpc/grpc                     1.57.0 gRPC library for PHP
guzzlehttp/guzzle             7.9.2  Guzzle is a PHP HTTP client library
guzzlehttp/promises           2.0.3  Guzzle promises library
guzzlehttp/psr7               2.7.0  PSR-7 message implementation that also provides common utility methods
monolog/monolog               3.7.0  Sends your logs to files, sockets, inboxes, databases and various web services
psr/cache                     3.0.0  Common interface for caching libraries
psr/http-client               1.0.3  Common interface for HTTP clients
psr/http-factory              1.1.0  PSR-17: Common interfaces for PSR-7 HTTP message factories
psr/http-message              2.0    Common interface for HTTP messages
psr/log                       3.0.2  Common interface for logging libraries
ralouphie/getallheaders       3.0.3  A polyfill for getallheaders.
ramsey/collection             2.0.0  A PHP library for representing and manipulating collections.
ramsey/uuid                   4.7.6  A PHP library for generating and working with universally unique identifiers (UUIDs).
rize/uri-template             0.3.8  PHP URI Template (RFC 6570) supports both expansion & extraction
symfony/deprecation-contracts 3.5.0  A generic function and convention to trigger deprecation notices

This looks like it'll be fixed with googleapis/gax-php#582 (or something similar). See #7187 for more info.

Thanks @bshaffer for the update. when we can expect release with this fix ?