google-cloud-pubsubgoogle-app-engine-pythonprotorpc

protoRPC: returning a pub/sub message python


How does one return a PubsubMessage through protoRPC ?

Pub/sub message example,

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

Solution

  • 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/