---
title: c Google Pub/Sub
description: Available connectors
documentId: ipaas-google-pubsub
locale: en-US
---

The [**Google Pub/Sub**](https://camel.apache.org/components/4.10.x/google-pubsub-component.html) component enables integration with Google Cloud Pub/Sub service for publishing and consuming messages. It is ideal for asynchronous communication between applications, facilitating data exchange in distributed scenarios.

**URI Syntax**: `google-pubsub:projectId:destinationName`

## Main fields

*Path parameters*

| **Name** | **Description** | **Default** | **Type** |
|----------|---------------|------------|----------|
| `projectId` (common) | (required) The Google Cloud Pub/Sub project ID. | —  | String |
| `destinationName` (common) | (required) The destination name. For the consumer (trigger), this will be the subscription name, while for the producer (connector), this will be the topic name. | —  | String |

*Query parameters*

| **Name** | **Description** | **Default** | **Type** |
|----------|---------------|------------|----------|
| `serviceAccountKey` (common) | The service account key that can be used as credentials for the Pub/Sub publisher/subscriber. It can be loaded by default from the classpath, but you can add the `classpath:`, `file:` or `http:` prefix to load the resource from different systems. | —  | String |

## Example


<Callout type="important" title="IMPORTANT">
Before executing the integration flow, create and import the Google Cloud service account key to a config map. This key will be used as a **resource** in the integration:

```
$ kubectl create configmap googlesa --from-file=key.json
configmap/googlesa created
```

The "key.json" file contains the service account credentials in JSON format. In Integrations, this key will be configured as a **Resource** file.

Read more about [Resources](/docs/integrations/ipaas-resources) files.
</Callout>

The following flow publishes a message to the `topic-01` topic in Google Pub/Sub. The message will be sent in the payload of a REST trigger.

<Steps>
<Step>
The flow starts with a POST request to the `/pubsub-01` endpoint with data in the body.
</Step>
<Step>
Then, it logs the received content using the `${body}` expression to display the message body.
</Step>
<Step>
Next, it converts the message body to `byte[]` type (byte array), as Google Pub/Sub requires this specific format.
</Step>
<Step>
Finally, it publishes the message to Google Pub/Sub:
- Project: `registry-ipaas-testing` (Google Cloud project ID)
- Topic: `topic-01` (topic name where the message will be published)
- Authentication: `key.json` (file containing the Google Cloud service account key)
- The converted content is published as a message to the topic.
</Step>
</Steps>

```yaml
      - from:
          uri: rest:post:/pubsub-01
          steps:
          - log:
              message: "got body ${body}"
          - convertBodyTo:
              type: byte[]              
          - to:
              uri: "google-pubsub:registry-ipaas-testing:topic-01"
              parameters:
                serviceAccountKey: key.json
```

![](https://creative-ball-51b3fc85c0.media.strapiapp.com/google_pubsub_connector_8aca4cfc57.png)

<Callout type="note" title="NOTE">
The `convertBodyTo` step is necessary because the REST component generates a body of type `Stream`, while Google Pub/Sub expects other types like `byte[]` or `String`. Apache Camel does not automatically convert from `Stream` to `byte[]`, resulting in an error.

The need for this conversion depends on the usage context. The flow would work equally with:

```yaml
- convertBodyTo:
    type: String
```

For more details about accepted types, see the [official component documentation](https://camel.apache.org/components/4.10.x/google-pubsub-component.html#_producer_endpoints).
</Callout>

### cURL

``` 
curl --location 'http://pubsub-01.a1b2c3d4e5.integrations-tst.sensedia-eng.com/pubsub-01' \
--header 'Content-Type: application/json' \
--data 'This was a message sent by Camel-K'
```

### Result

![](https://creative-ball-51b3fc85c0.media.strapiapp.com/google_pubsub_result_03e4120859.png)
