Google Pub/Sub for Message Sync
If you want to sync data between Gmail and Nylas even faster, you can use Google Pub/Sub for real-time syncing of Gmail messages. This guide will take you through the set up process.
Prerequisites
- An existing Google app connected to your Nylas application.
Step 1: Create a Service Account
-
Go to the project you created for use with Nylas.
-
In the search bar, type Service Accounts.
-
On the screen that opens, click CREATE SERVICE ACCOUNT.
-
Give the account the name
nylas-gmail-realtime
.The name,
nylas-gmail-realtime
, is required for the integration to work. -
Leave Grant this service account access to project (optional) and Grant users access to this service account (optional) blank.
-
Click Done.
Step 2: Create Pub/Sub Topic
- In the search bar look for pub sub and select Pub/Sub.
- Click CREATE TOPIC.
- Enter the topic ID
nylas-gmail-realtime
, and leave the defaults checked. The topic ID listed is required for the integration to work. - On the next page, click SHOW INFO PANEL, if it's not already open.
- In the panel click ADD PRINCIPAL.
- Add the principal
[email protected]
. - Set the role to Pub/Sub Publisher.
- On save you should be directed to the Topics page.
- On the Topics page find the Subscriptions section. Click
nylas-gmail-realtime-sub
. - Click the subscription, then click edit.
- Change the following:
- Delivery type: Push
- Endpoint URL:
https://gmailrealtime.us.nylas.com
- Select Enable Authentication and choose the service account you made in Create a Service Account.
- When prompted, grant the
roles/iam.serviceAccountTokenCreator
to your service account. - Leave the other fields as default and click Update.
- After saving, it will take you back to the Subscription page. Copy the Topic Name for the next step.
The topic name must be nylas-gmail-realtime
. The principal must use the email [email protected]
for Google Pub/Sub to work.
Step 3: Add the Topic Name to Your Dashboard
Before adding the Topic name, we need to enable Google Pub/Sub for your application.
- Go to App Settings.
- Click on the Authentication tab and go to Google Auth. There is a input called GCP Topic Name. Input the topic created in Create a Pub/Sub Topic, for example,
projects/nylas-test/topics/nylas-gmail-realtime
. - Repeat steps one and two for every Nylas app you would like real-time Gmail message sync for.
- You can use the same Pub/Sub topic for all your Nylas apps.