This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.
Working with Project Topics in Google Pub/Sub
Overview
The following operations allow you to work with project topics. Click an operation name to see details on how to use it.
For a sample proxy service that illustrates how to work with project topics, see Sample configuration.
Operation | Description |
---|---|
Creates a new topic. | |
publishMessage | Publishes messages to a specified topic. |
Operation details
This section provides more details on each of the operations.
Creating a topic
The createTopic
operation creates a new topic with the name that you specify.
<googlepubsub.createTopic> <topicName>{$ctx:topicName}</topicName> <projectId>{$ctx:projectId}</projectId> </googlepubsub.createTopic>
Properties
topicName
: The name that you want to give the topic that you are creating.projectId
:Â The unique ID of the project within which you want to create a topic.
Sample request
Following is a sample request that can be handled by the createTopic
operation:
{ "apiUrl":"https://pubsub.googleapis.com", "apiVersion":"v1", "accessToken": "ya29.GlwABYxVvbJG2NhgX_NQhxjtF_0G9bzf0FEj_shNWgF_GXmYFpwIxjeYQF0XQXrBjjcrJukforOeyTAHoFfSQW0x-OrrZ2lj47Z6k6DAYZuUv3ZhJMl-ll4mvouAbc", "topicName":"topicA", "projectId":"rising-parser-123456" }
Related Google Pub/Sub documentation
https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/create
Publishing messages
The publishMessage
operation publishes a message to a specified topic.
<googlepubsub.publishMessage> <topicName>{$ctx:topicName}</topicName> <projectId>{$ctx:projectId}</projectId> <data>{$ctx:data}</data> <attributes>{$ctx:attributes}</attributes> </googlepubsub.publishMessage>
Properties
topicName
:Â The unique name of the topic to which the message is to be published.projectId
:Â The unique ID of the project within which the topic is created.data
: The message payload.attributes
[Optional]: Additional attributes for the message.
Sample request
Following is a sample request that can be handled by the publishMessage
operation.
{ "apiUrl":"https://pubsub.googleapis.com", "apiVersion":"v1", "accessToken": "ya29.GlwABYxVvbJG2NhgX_NQhxjtF_0G9bzf0FEj_shNWgF_GXmYFpwIxjeYQF0XQXrBjjcrJukforOeyTAHoFfSQW0x-OrrZ2lj47Z6k6DAYZuUv3ZhJMl-ll4mvouAbc", "projectId":"rising-parser-123456", "topicName":"topicA", "data":"hi", "attributes:{"key": "value1","key2":"values2"} }
Related Google pub/sub documentation
https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/publish
Sample configuration
Following is a sample proxy service that illustrates how to connect to Google Pub/Sub with the init
operation, and then use the createTopic
operation. The sample request for this proxy can be found in createTopic
 sample request. You can use this sample as a template for using other operations in this category.
<?xml version="1.0" encoding="UTF-8"?> <proxy xmlns="http://ws.apache.org/ns/synapse" name="createTopic" startOnLoad="true" statistics="disable" trace="disable" transports="http,https"> <target> <inSequence> <property expression="json-eval($.accessToken)" name="accessToken"/> <property expression="json-eval($.apiUrl)" name="apiUrl"/> <property expression="json-eval($.apiVersion)" name="apiVersion"/> <property name="topicName" expression="json-eval($.topicName)"/> <property name="projectId" expression="json-eval($.projectId)"/> <googlepubsub.init> <apiUrl>{$ctx:apiUrl}</apiUrl> <apiVersion>{$ctx:apiVersion}</apiVersion> <accessToken>{$ctx:accessToken}</accessToken> </googlepubsub.init> <googlepubsub.createTopic> <topicName>{$ctx:topicName}</topicName> <projectId>{$ctx:projectId}</projectId> </googlepubsub.createTopic> <respond/> </inSequence> <outSequence> <log/> <send/> </outSequence> </target> </proxy>