Contents
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.
In StreamBase Studio, import this sample with the following steps:
-
From the top-level menu, select
> . -
Enter
protobuf
orgoogle
to narrow the list of options. -
Select Google Protocol Buffers (protobuf) conversion from the StreamBase Standard Adapters category.
-
Click
.
StreamBase Studio creates a single project for the Protobuf adapter samples in your current Studio workspace.
Run this sample in Studio as follows:
-
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
> from the context menu. -
Open the
src/main/eventflow/
folder.packageName
-
Double-click to open the
protobuf.sbapp
application, then click theRun button. This opens the SB Test/Debug perspective and starts the application.
-
In the Manual Input view, select the SimpleInputStream input stream.
-
Enter values in the
id
,name
,phones
andaddress
(postal code and street) fields. You can leave values blank, but do not leave the default value asnull
. For the phones list field, enter as many phone numbers as you want. -
Click
. -
Observe your message emitted on both the Tuple2ProtobufOutput and RegenerateTuple output streams.
-
Select the Protobuf Input adapter (in either EventFlow), click the Operator Properties tab, and uncheck Enable Pass Through Fields.
-
Send the data again and observe the regenerateTuple output stream.
-
Experiment with different Input Stream schemas by double-clicking the Input Stream and clicking the Edit Schema tab.
-
In the Manual Input view, select the InputStream input stream.
-
Enter values in the
id
,name
,phones
andaddress
(postal code and street) fields. You can leave values blank, but do not leave the default value asnull
. For the phones list field, enter as many phone numbers as you want. -
Click
. -
Observe your message emitted on both the Tuple2ProtobufWithDescOutput and RegenerateTupleWithDesc output streams.
-
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.
-
To experiment with different Protobuf schemas, double-click the Protobuf Input adapter (in either EventFlow) and click the Edit Schema tab.
-
When done, press F9 or click the
Stop Running Application button.
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; } }
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.