The Google Pub/Sub 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
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 |
IMPORTANTBefore 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:
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 files.
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.
The flow starts with a POST request to the /pubsub-01 endpoint with data in the body.
Then, it logs the received content using the ${body} expression to display the message body.
Next, it converts the message body to byte[] type (byte array), as Google Pub/Sub requires this specific format.
Finally, it publishes the message to Google Pub/Sub:
registry-ipaas-testing (Google Cloud project ID)topic-01 (topic name where the message will be published)key.json (file containing the Google Cloud service account key)
NOTEThe
convertBodyTostep is necessary because the REST component generates a body of typeStream, while Google Pub/Sub expects other types likebyte[]orString. Apache Camel does not automatically convert fromStreamtobyte[], resulting in an error.The need for this conversion depends on the usage context. The flow would work equally with:
For more details about accepted types, see the official component documentation.

We use cookies to enhance your experience on our site. By continuing to browse, you agree to our use of cookies.Learn more