Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't reach GCP PubSub Emulator #825

Closed
PabloRR100 opened this issue Nov 17, 2022 · 1 comment
Closed

Can't reach GCP PubSub Emulator #825

PabloRR100 opened this issue Nov 17, 2022 · 1 comment
Assignees
Labels
api: pubsub Issues related to the googleapis/python-pubsub API. type: question Request for information or clarification. Not an issue.

Comments

@PabloRR100
Copy link

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 !

@product-auto-label product-auto-label bot added the api: pubsub Issues related to the googleapis/python-pubsub API. label Nov 17, 2022
@acocuzzo
Copy link
Contributor

Please set the host to localhost:8085 to match the hostname the emulator is running on.

@acocuzzo acocuzzo self-assigned this Nov 23, 2022
@acocuzzo acocuzzo added the type: question Request for information or clarification. Not an issue. label Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the googleapis/python-pubsub API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

2 participants