Skip to content

Can't reach GCP PubSub Emulator #825

Closed
@PabloRR100

Description

@PabloRR100

I have setup the PubSub emulator to run a Python script locally pointing to it.
The emulator is run following the tutorial and it seems to be working fine:

➜ gcloud beta emulators pubsub start --project=tokyo-rain-123 --host-port=127.0.0.1:8085
Executing: /Users/pabloruiz/Downloads/google-cloud-sdk/platform/pubsub-emulator/bin/cloud-pubsub-emulator --host=127.0.0.1 --port=8085
[pubsub] This is the Google Pub/Sub fake.
[pubsub] Implementation may be incomplete or differ from the real system.
[pubsub] Nov 17, 2022 3:32:04 PM com.google.cloud.pubsub.testing.v1.Main main
[pubsub] INFO: IAM integration is disabled. IAM policy methods and ACL checks are not supported
[pubsub] SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
[pubsub] SLF4J: Defaulting to no-operation (NOP) logger implementation
[pubsub] SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[pubsub] Nov 17, 2022 3:32:04 PM com.google.cloud.pubsub.testing.v1.Main main
[pubsub] INFO: Server started, listening on 8085

It is working fine using curl:

➜ curl -X PUT http://localhost:8085/v1/projects/tokyo-rain-123/topics/topic-data1
{
  "name": "projects/tokyo-rain-123/topics/topic-data1"
}

Although it is displaying this warning on the emulator:

[pubsub] INFO: Server started, listening on 8085
[pubsub] Nov 17, 2022 4:00:57 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
[pubsub] INFO: Detected non-HTTP/2 connection.
[pubsub] Nov 17, 2022 4:00:57 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
[pubsub] INFO: Detected HTTP/2 connection.

If I try it with the Python client, it just never reaches the server, since I can't see anything in the logs. This is the Python scripts:

import logging
import os
from dotenv import load_dotenv
from google.cloud import pubsub_v1

load_dotenv()
logger = logging.getLogger(__name__)

HOST, PROJECT_ID = os.environ.get("PUBSUB_EMULATOR_HOST"), os.environ.get("PUBSUB_PROJECT_ID")
print(f"Host: {HOST}, Project ID: {PROJECT_ID}")

publisher = pubsub_v1.PublisherClient()

def list_topics(project_id):
    project_path = f"projects/{project_id}"
    all_topics = list(publisher.list_topics(
        request={"project": project_path},
        timeout=5
    ))
    print(f"Found {len(all_topics)}")
    return all_topics


logger.info("Listing topics for project:")
topics = list_topics(project_id=PROJECT_ID)
for topic in topics:
    logger.info(topics)

which is just printing the correct env variables, but the client never gets a response for the rpc call.

Host: [::1]:8085, Project ID: tokyo-rain-123

Any idea why this is happening ?

Thanks in advance !

Metadata

Metadata

Assignees

Labels

api: pubsubIssues related to the googleapis/python-pubsub API.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions