1. Home
  2. ...
  3. Messaging and Notification
  4. c Google Pub/Sub

c Google Pub/Sub

Available connectors

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

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

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:

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:

  • 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.

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:

For more details about accepted types, see the official component documentation.

cURL

Result

How happy are you with this page?

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