Google Protocol Buffers Sample

Introduction

This topic describes how to run the sample application for the TIBCO Adapters for Google Protocol Buffers (Protobuf for short), and illustrates how to use the Protobuf adapters to convert messages into Protobuf type byte arrays as well as parse the byte arrays into a customized messages.

The sample, protobuf.sbapp, demonstrates a complete process of serializing tuple messages into a Protobuf type byte array and deserializing back to tuple messages, based on a customized descriptor file.

Importing This Sample into StreamBase Studio

In StreamBase Studio, import this sample with the following steps:

  • From the top-level menu, select File>Import Samples and Community Content.

  • Enter protobuf or google to narrow the list of options.

  • Select Google Protocol Buffers (protobuf) conversion from the StreamBase Standard Adapters category.

  • Click Import Now.

StreamBase Studio creates a single project for the Protobuf adapter samples in your current Studio workspace.

Running the Protobuf Sample in StreamBase Studio

Run this sample in Studio as follows:

  1. In the Project Explorer view, open the sample you just loaded.

    If you see red marks on a project folder, wait a moment for the project to load its features.

    If the red marks do not resolve themselves after a minute, select the project, right-click, and select Maven>Update Project from the context menu.

  2. Open the src/main/eventflow/packageName folder.

  3. Double-click to open the protobuf.sbapp application, then click the Run button. This opens the SB Test/Debug perspective and starts the application.

  4. In the Manual Input view, select the SimpleInputStream input stream.

  5. Enter values in the id, name, phones and address (postal code and street) fields. You can leave values blank, but do not leave the default value as null. For the phones list field, enter as many phone numbers as you want.

  6. Click Send Data.

  7. Observe your message emitted on both the Tuple2ProtobufOutput and RegenerateTuple output streams.

  8. Select the Protobuf Input adapter (in either EventFlow), click the Operator Properties tab, and uncheck Enable Pass Through Fields.

  9. Send the data again and observe the regenerateTuple output stream.

  10. Experiment with different Input Stream schemas by double-clicking the Input Stream and clicking the Edit Schema tab.

  11. In the Manual Input view, select the InputStream input stream.

  12. Enter values in the id, name, phones and address (postal code and street) fields. You can leave values blank, but do not leave the default value as null. For the phones list field, enter as many phone numbers as you want.

  13. Click Send Data.

  14. Observe your message emitted on both the Tuple2ProtobufWithDescOutput and RegenerateTupleWithDesc output streams.

  15. To experiment with different descriptor files, double-click the Tuple2ProtobufWithDesc Protobuf Output adapter, click its Operator Properties tab, and select different files from the drop-down list.

  16. To experiment with different Protobuf schemas, double-click the Protobuf Input adapter (in either EventFlow) and click the Edit Schema tab.

  17. When done, press F9 or click the Stop Running Application button.

Customized Descriptor

When you want to customize the output schema for the message, you must provide a descriptor file that compiles from a Google Protobuf proto.

And the descriptor file can be generated by command line:

protoc protoFile.proto --descriptor_set_out=descFile.desc

Below is an example of a proto file:

syntax = "proto3";
import "google/protobuf/descriptor.proto";
message Input {
  string name = 1;
  int32 id = 2;  // Unique ID number for this person.
  Address add = 3;
  repeated PhoneNumber phones = 4;  //List
  
    message PhoneNumber {
        string number = 1;
    }
  
    message Address {
        string zip = 1;
        string street = 2;
    }
}

Sample Location

When you load the sample into StreamBase Studio, Studio copies the sample project's files to your Studio workspace, which is normally part of your home directory, with full access rights.

Important

Load this sample in StreamBase Studio, and thereafter use the Studio workspace copy of the sample to run and test it, even when running from the command prompt.

Using the workspace copy of the sample avoids permission problems. The default workspace location for this sample is:

studio-workspace/sample_adapter_embedded_protobuf

See Default Installation Directories for the default location of studio-workspace on your system.