Receiving Messages from a Google Pub/Sub Topic


This application demonstrates how to configure WSO2 Streaming Integrator Tooling using googlepubsub source in Siddhi to consume events. Events which are in TEXT format are consumed from a googlepubsub topic.


  1. Create a Google Cloud Platform account.
  2. Sign in to Google Account and set up a GCP Console project and enable the API.
  3. Create a service account and download a private key as JSON.
  4. Place your json file in any system folder and provide the path for the credential.path.
  5. Save the sample.
  6. If there is no syntax error, the following message is shown on the console: * -Siddhi App ReceiveGooglePubSubMesssage successfully deployed.

Executing the Sample:

  1. Start the Siddhi application by clicking on 'Run'
  2. If the Siddhi application starts successfully, the following messages would be shown on the console,
  3. ReceiveGooglePubSubMesssage.siddhi - Started Successfully!

Testing the Sample:

  1. Receive events through the following, You may listen to the events coming to a topic after the subscription is made.

Viewing the Results:

See the output on the terminal:
INFO {} - ReceiveEvent : BarStream : Event{timestamp=1552548124599, data=[message:"Hello"], isExpired=false} (Encoded)


Make sure the the credential file is correct and user have write access to make api calls.

Stop this Siddhi application


@App:description('Consume messages from a googlepubsub Topic.')

@App:description("Listen for messages received for a topic in Google Pub Sub Server.")

@source(type ='googlepubsub', 
       = 'sp-path-1547649404768', 
       = 'topic75',
                credential.path = '/../sp.json',
       = 'sub75', 
                @map(type = 'text'))

define stream FooStream (message string); 

define stream BarStream(message string);

    from FooStream 
    select message 
    insert into BarStream;