Skip to content

unclear docs on https://googlecloudplatform.github.io/google-cloud-python/latest/pubsub/#publishing #4123

Description

@ensonic

The docs have this example:

publisher=pubsub.PublisherClient()
topic='projects/{project_id}/topics/{topic}'.format(
project_id=os.getenv('GOOGLE_CLOUD_PROJECT'),
topic='MY_TOPIC_NAME', # Set this to something appropriate.
)
publisher.create_topic()
publisher.publish(topic, b'My first message!', spam='eggs')

should it be:

publisher=pubsub.PublisherClient()
topic_path='projects/{project_id}/topics/{topic}'.format(
project_id=os.getenv('GOOGLE_CLOUD_PROJECT'),
topic='MY_TOPIC_NAME', # Set this to something appropriate.
)
topic=publisher.create_topic(topic_path)
publisher.publish(topic, b'My first message!', spam='eggs')

main questions:

  • how does publisher.create_topic() know what topic if we don't tell it
  • is there still a a topic object as there was before 0.28.0?
  • can we just create a topic regardless whether it is already there? The old code (pre 0.28.0) was doing:
client=pubsub.Client()
topic=client.topic(topic_name)
ifnottopic.exists():
topic.create()

Metadata

Metadata

Assignees

Labels

api: pubsubIssues related to the Pub/Sub 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