|
| 1 | +# Event Source for Google Cloud Pub/Sub |
| 2 | + |
| 3 | +This event source subscribes to messages sent to a [Google Cloud Pub/Sub][gc-pubsub] topic. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +### Service Account |
| 8 | + |
| 9 | +A [Service Account][gc-pubsub-svcacc] is required to authenticate the event source and allow it to interact with Google |
| 10 | +Cloud Pub/Sub. You can create a service account by following the instructions at [Creating and managing service |
| 11 | +accounts][gc-iam-svcacc]. |
| 12 | + |
| 13 | +The service account must be granted an [IAM Role][gc-iam-roles] with at least the following permissions: |
| 14 | + |
| 15 | +- `pubsub.subscriptions.consume` |
| 16 | +- `pubsub.subscriptions.get` |
| 17 | + |
| 18 | +The following set of permissions is also required if you delegate the management of the Pub/Sub subscription to the |
| 19 | +event source. In case you prefer to manage the subscription yourself, these can be safely be omitted. More details on |
| 20 | +that topic are provided in the [Pub/Sub Subscription](#pubsub-subscription-optional) section below. |
| 21 | + |
| 22 | +- `pubsub.subscriptions.create` |
| 23 | +- `pubsub.subscriptions.delete` |
| 24 | + |
| 25 | +The predefined `roles/pubsub.editor` role is one example of role that is suitable for use with the TriggerMesh event |
| 26 | +source for Google Cloud Pub/Sub. |
| 27 | + |
| 28 | +<!-- NOTE(antoineco): image from googlecloudstorage source purposely reused for simplicity --> |
| 29 | + |
| 30 | + |
| 31 | +Create a [key in JSON format][gc-iam-key] for this service account and save it. This key is required to be able to run |
| 32 | +an instance of the Google Cloud Pub/Sub event source. |
| 33 | + |
| 34 | +### Pub/Sub Topic |
| 35 | + |
| 36 | +If you don't already have a Pub/Sub topic to subscribe to, create one by following the instructions at [Managing topics |
| 37 | +and subscriptions][gc-pubsub-adm]. |
| 38 | + |
| 39 | +Take note of the full [topic name][gc-pubsub-resname], it is a required input to be able to run an instance of the |
| 40 | +Google Cloud Pub/Sub event source. |
| 41 | + |
| 42 | +<!-- NOTE(antoineco): image from googlecloudstorage source purposely reused for simplicity --> |
| 43 | + |
| 44 | + |
| 45 | +### Pub/Sub Subscription _(optional)_ |
| 46 | + |
| 47 | +A subscription is required in order to allow the TriggerMesh event source for Google Cloud Pub/Sub to pull messages |
| 48 | +from a Pub/Sub topic. |
| 49 | + |
| 50 | +This section can be skipped if you would like to let the event source manage its own subscription, which is the default |
| 51 | +behaviour. In this case, please simply ensure you granted all necessary permissions to the service account in the |
| 52 | +previous section. |
| 53 | + |
| 54 | +If, however, you prefer messages to be pulled using a subscription which you manage yourself, please ensure that |
| 55 | +subscription is a "pull" subscription as described in the documentation page [Managing topics and |
| 56 | +subscriptions][gc-pubsub-adm]. |
| 57 | + |
| 58 | +<!-- NOTE(antoineco): image from googlecloudstorage source purposely reused for simplicity --> |
| 59 | + |
| 60 | + |
| 61 | +## Deploying an Instance of the Source |
| 62 | + |
| 63 | +Open the Bridge creation screen and add a source of type `Google Cloud Pub/Sub`. |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | +In the Source creation form, give a name to the event source and add the following information: |
| 68 | + |
| 69 | +* [**Secret**][gc-iam-key]: Service account key in JSON format, as described in the previous sections. |
| 70 | +* [**Topic**][gc-pubsub-resname]: Full resource name of the Pub/Sub topic to subscribe to. |
| 71 | +* **Subscription ID**: _(optional)_ ID of the subscription to use for pulling messages from the Pub/Sub topic, in case |
| 72 | + you prefer to manage this subscription yourself as described in the previous sections. |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | +After clicking the `Save` button, you will be taken back to the Bridge editor. Proceed to adding the remaining |
| 77 | +components to the Bridge, then submit it. |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | +A ready status on the main _Bridges_ page indicates that the event source is ready to consume messages from the Pub/Sub |
| 82 | +topic. |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | +## Event Types |
| 87 | + |
| 88 | +The TriggerMesh event source for Google Cloud Pub/Sub emits events of the following type: |
| 89 | + |
| 90 | +* `com.google.cloud.pubsub.message` |
| 91 | + |
| 92 | +[gc-pubsub]: https://cloud.google.com/pubsub |
| 93 | +[gc-pubsub-svcacc]: https://cloud.google.com/pubsub/docs/authentication#service-accounts |
| 94 | +[gc-pubsub-adm]: https://cloud.google.com/pubsub/docs/admin |
| 95 | +[gc-pubsub-resname]: https://cloud.google.com/pubsub/docs/admin#resource_names |
| 96 | +[gc-iam-svcacc]: https://cloud.google.com/iam/docs/creating-managing-service-accounts |
| 97 | +[gc-iam-key]: https://cloud.google.com/iam/docs/creating-managing-service-account-keys |
| 98 | +[gc-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles |
0 commit comments