Tuesday 28 November 2023

How to use PublisherServiceAsyncClient

I am trying to use AsyncPublisherClient from pubsublite

pip install google-cloud-pubsublite==1.8.3
from google.cloud import pubsublite_v1

pubsub = pubsublite_v1.AsyncPublisherClient()

error: Module has no attribute "AsyncPublisherClient"

The documentation is very scarce and I couldn't even find this class in the virtualenv directory, just its interface.

How do I use this library?

EDIT: It looks like the correct class is PublisherServiceAsyncClient


EDIT2:

from google.cloud.pubsublite_v1.types.publisher import PublishRequest
from google.cloud.pubsublite_v1.types import PubSubMessage
from google.cloud.pubsublite_v1 import PublisherServiceAsyncClient

pubsub = PublisherServiceAsyncClient()

message = PubSubMessage(data=json.dumps(payload).encode("utf-8"))

request = PublishRequest(topic=os.environ["TOPIC"], messages=[message])

async def request_generator():
    yield request

await pubsub.publish(requests=request_generator())

ValueError: Unknown field for PublishRequest: topic



from How to use PublisherServiceAsyncClient

No comments:

Post a Comment