protoRPC: returning a pub/sub message python

343 Views Asked by At

How does one return a PubsubMessage through protoRPC ?

Pub/sub message example,

.{
  "data": string,
  "attributes": {
    string: string,
    ...
  },
  "messageId": string,
  "publishTime": string
}
1

There are 1 best solutions below

1
On BEST ANSWER

As first step you have to use Cloud Pub/Sub Client Libraries (Python) to subscribe to data in Cloud Pub/Sub, you create a subscription based on the topic, and subscribe to that.

You have to define a callback that process each received message. {1}

You can check the Hello World of Google Protocol RPC to pass the received message in the callback to the RPC service. {2}

{1}: https://google-cloud-python.readthedocs.io/en/latest/pubsub/

{2}: https://cloud.google.com/appengine/docs/standard/python/tools/protorpc/