Define a stream type
Rather than separately define the schema (stream type) in the declaration of each stream, create a type first so that each stream can simply refer to that type. Keeping the type definition in one place eliminates code duplication, and improves consistency and maintainability.
Create a type named
LocationType for the vehicle location data that will be the main kind of tuple flowing through the application.
Use the following information to create the stream type:
|id||rstring||Vehicle ID (an rstring uses “raw” 8-bit characters)|
(milliseconds since 00:00:00 on January 1, 1970)
|speed||float64||Vehicle speed (km/h)|
|heading||float64||Direction of travel (degrees, clockwise from north)|
To define a stream type:
- In the graphical editor, right-click anywhere on the canvas outside the main composite (MyMainComposite), and click Edit.
You see a Properties view, which floats above all the other views. Be sure that it looks the same as the following screen capture with the three tabs for General, Uses, and Types. If your Properties view does not look the same as the screen capture, dismiss the view and right-click again in the graphical editor outside the main composite.
- In the Properties view, click Types.
- Click Add New Type in the Name column.
LocationType, and then press Enter.
- Click Add Attribute below LocationType in the Name column, and enter
- Press the Tab key to go to the Type column, and enter
Tip for content assist: In the Type column, press Ctrl+Space to get a list of available types. Begin typing (for example, “r” for
rstring) to narrow down the list. When the type you want is selected, press Enter to assign it to the field. This reduces keyboard effort and typing errors.
- Press the Tab key to go to the next Name field.
- Enter the attribute names and types listed in the table above.
- Leave the Properties view open.
Tip for obscured views: The floating Properties view might obscure other views. An alternative is to use the Properties tab in the view at the bottom of the perspective.
- Check your results. The fields should look like the following screen capture:
The tuple type LocationType is now available for you to use as a stream type in any main composite within the namespace my.name.space.