
[Google Could Pub/Sub](https://cloud.google.com/pubsub/docs/overview) is a messaging service for exchanging event data among applications and services. It lets you create systems of event producers and consumers, called **publishers** and **subscribers**. Publishers communicate with subscribers asynchronously by broadcasting events to a **topic**, without regard to how or when these events are to be processed. Pub/Sub then delivers events to all the subscribers of that topic, and each subscriber has its own logic of reacting to the event. 

The integration between Synerise and this tool opens up possibilities of exporting data collected in Synerise. With the **Publish Message** node, you can push data from Synerise to Pub/Sub in the form of messages published to Pub/Sub queues in [the CloudEvents standard](https://cloudevents.io/). You can use this connection in various scenarios, such as exporting transactions, event data, customer information (such as marketing agreements), results of [metrics](/docs/analytics/metrics), [aggregates](/docs/analytics/aggregates/introduction-to-aggregates), [expressions](/docs/analytics/expressions/introduction-to-expressions), [reports](/docs/analytics/reports/introduction-to-reports), and many more to Google Cloud Pub/Sub. This lets you seamlessly integrate Synerise with third-party tools or other Google Tools such as Google Analytics, Google Ads, Google BigQuery, Google Sheets.

During the configuration of the node, you can use [Jinjava inserts](/developers/inserts/automation) which let you dynamically refer to the profile attributes and event parameters in the workflow.


<div class="admonition admonition-important"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg></div><div class="admonition-body"><div class="admonition-content">

This node is not optimized for batch operations that send large volumes of data (for example, updating all events for each profile). Use it to export changes within one event, profile attribute (for example, marketing agreement), analysis results, and so on.

</div></div></div>



<div class="admonition admonition-note"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg></div><div class="admonition-body"><div class="admonition-content">

We recommend publishing data in Google Pub/Sub using the CloudEvents standard, however if you want to publish a message out of this standard or if you want to publish more than one message at once, proceed with ["Publish Raw Message" node](/docs/automation/integration/google-cloud-pubsub/publish-raw-messages).

</div></div></div>


## Prerequisites
---
- Set up [the Google Cloud Console project](https://console.cloud.google.com/) and enable the Pub/Sub API for that project.
- Configure [publishing and consuming messages in Pub/Sub](https://cloud.google.com/pubsub/docs/publish-receive-messages-console).
- Become familiar with [building message frames in Google Cloud Pub/Sub](https://cloud.google.com/pubsub/docs/reference/rest/v1/PubsubMessage).
- Become familiar with the [CloudEvents standard](https://cloudevents.io/) that Synerise uses to send data.
- [Learn how CloudEvents are sent within the Pub/Sub message](https://github.com/google/knative-gcp/blob/main/docs/spec/pubsub-protocol-binding.md#32-structured-content-mode).

### Node configuration
---
1. Click **Google Cloud Pub/Sub > Publish Message**. 
2. Click **Select connection**.  
3. From the dropdown list, select the connection.  
   - If no connections are available or you want to create a new one, see [Create a connection](#create-a-connection).
   - If you selected an existing connection, proceed to [defining the integration settings](#define-the-integration-settings).

### Create a connection
To allow the data exchange, establish a connection between Synerise and Google Cloud Pub/Sub.  

1. At the bottom of the **Select connection** dropdown list, click **Add connection**.  
2. On the pop-up, click **Sign in with Google**.
3. Select a Google account which has:  
    - Access to the project and topic in Google Cloud Pub/Sub that you want to use.
    - Permissions to publish messages in that project and topic.
4. Follow the instructions on the interface.
5. After successful authentication, click **Next**.  
6. In the **Connection name** field, enter the name of the connection.  
    It's used to find the connection on the list.
7. Click **Apply**.  
        **Result**: A connection is created and selected. 

### Define the integration settings
In this step, fill in the form that allows you to publish a message in Google Cloud Pub/Sub in CloudEvents standard.

<figure><img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/docs/automation/_gfx/publish-a-message.png" class="medium" alt="A blank configuration form in the Publish Message node"><figcaption>A blank configuration form in the Publish Message node</figcaption></figure>  


<div class="admonition admonition-note"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg></div><div class="admonition-body"><div class="admonition-content">

Fields marked with the <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/snippet-icon.png" alt="Snippet icon" class="icon" > icon accept [snippets](/docs/assets/snippets) or [inserts](/developers/inserts). This integration allows usage of profile-related inserts.

</div></div></div>


1. In the **Project ID** field, enter the unique identifier of your project in Google Cloud Console.  
    You can learn how to find the project ID [here](https://support.google.com/googleapi/answer/7014113).
2. In the **Topic ID** field, enter the unique identifier of the topic (a named resource that represents a feed of messages). Learn more about [creating and managing topics](https://cloud.google.com/pubsub/docs/create-topic).
3. In the **Attributes (optional)** field, enter a JSON key-value object with message attributes.  
    This can be used to filter messages in the subscription. Learn more about [building the "attributes" object](https://cloud.google.com/pubsub/docs/reference/rest/v1/PubsubMessage). The Attributes object can contain up to 100 attributes.
    
   <details class="accordion"><summary>Click here to see example of Attributes object</summary><div class="accordion-content"><pre><code class="language-json">{ "cardID": "XXX" }</code></pre></div></details>


4. In the **CloudEvent type** field, enter the type of data sent in the CloudEvent.  
    Learn more about [CloudEvent types](https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/spec.md#type).
5. In the **Data (optional)** field, enter the event data.  
    It will be sent to Pub/Sub as the `data` object in a [CloudEvent JSON Object](https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/formats/json-format.md). The CloudEvent object will be automatically encoded with base64 and sent as the `data` field in a [Pub/Sub Message](https://cloud.google.com/pubsub/docs/reference/rest/v1/PubsubMessage). 


    
   <details class="accordion"><summary>Click here to see example of the Data field</summary><div class="accordion-content"><pre><code class="language-json">{ "name": "John", "age": 30, "hasCard": true }</code></pre></div></details>


6. Confirm the settings by clicking **Apply**.  
    **Result**: When the Publish Message node is executed, a [`pubSub.publishMessage` event](/docs/assets/events/event-reference/integration#pubsubpublishmessage) is generated on the activity list of the profile who is the actor in the workflow.


   <div class="admonition admonition-note"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg></div><div class="admonition-body"><div class="admonition-content">

   When publishing the message in CloudEvents standard to Pub/Sub, Synerise ads the following parameters automatically to `data` object in the message body:
   -  `specversion` with the value `1.0`,
   - `type` with the value entered in **CloudEvent type** field,
   - `time` with the time of publishing the message,
   - `source` with the value `/synerise/automation/{workflowID}`, where `{workflowID}` part is replaced with the ID of the automation workflow,
   - `id` with the unique hash generated automatically,
   - `datacontenttype` with the value `application/json; charset=utf-8`,
   - `subject` with `/synerise/automation/journeyId/{journeyID}` value, where `{journeyID}` is replaced with the ID of the automation journey.

   </div></div></div>


### Test integration
---

You can run a test request. If the request body contains a dynamic reference to a profile attribute and/or an event data from preceding nodes, then you can define the context using [test profile data](/docs/settings/configuration/test-profiles). 


<div class="admonition admonition-note"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg></div><div class="admonition-body"><div class="admonition-content">

Complete description of the feature is available in [Testing outgoing integrations](/docs/automation/test-requests-for-outgoing-integrations).

</div></div></div>



1. In the **Test integration** section, click **Send test request**.  
    **Result**: A test request builder opens. If:
    - a request body contains dynamic references, the request preview appears after you select the context of test profiles and events.
    - a request body contains static data, the preview of the body request appears immediately.
    <figure><img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/docs/automation/_gfx/test-request-builder-empty.png" class="large" alt="An empty test request builder"><figcaption>An empty test request builder</figcaption></figure>
2. If your request contains dynamic references (otherwise, the options aren't available):   
    - From the **Test profile** dropdown, select a test profile in the context of whom the test request will be performed.  
    - From the **Event context** dropdown list, you can select a particular occurrence of an event  whose values/information will be used for the test request.  
        1. Select a test profile.  
            **Result**: A history of test profile events appears.  
            <figure><img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/docs/automation/_gfx/event-stream-test-profile.png" class="large" alt="A stream of events of a test profile"><figcaption>A stream of events of a test profile</figcaption></figure> 
        2. From the list of events, select one whose data you want use as a context. If there is no event you can use, in the upper-right corner of the pop-up, click **Define own event** and provide the body of the event.
        3. Confirm by clicking **Apply**. 
3. Verify the request body. If there is something you want to change, come back to the node settings from previous steps.  
3. If the request body is ready to test, in the upper-right corner, click **Send request**.  
    **Result**: The response section appears and the **Update response event** button becomes active.  
4. Optionally, you can update response event with new parameters by clicking **Update response event** in the upper-right corner.


## Example of use
---
Refer to this use case to see how you can use this node:
- [Sending NPS survey results to Google Cloud Pub/Sub](/use-cases/send-nps-event-to-pubsub)