How to enqueue a list of tuples using the StreamBase .NET API

How to enqueue a list of tuples using the StreamBase .NET API

book

Article ID: KB0076093

calendar_today

Updated On:

Products Versions
TIBCO Streaming -

Description

How to enqueue a list of tuples using the StreamBase .NET API.

Issue/Introduction

Code example

Resolution

First, create a Tuple object for the sub-tuple list element as well as Field objects for the sub-tuple's fields.  Then, create a List of type 'object' and use the SetList() method in the StreamBase .NET API to set the value of your List field.

For a working example, you may enhance the SimpleEnqueuer.cs code provided in the StreamBase .NET Client Sample as follows:

  1. Add a second Input Stream named 'SubTupleSchemaIn' to the dotnet.sbapp module (located in the project root) with the sub-tuple's fields:  'subField1' (int) and 'subField2' (string).

  2. Add the 'SubTupleSchemaIn' stream to SimpleEnqueuer.cs:
 
// server and stream names
private static string SERVER = "sb://localhost:10000";
private static string INPUT_STREAM = "InputStream1";
private static string SUBTUPLE_STREAM = "SubTupleSchemaIn"; //add

  3. Add the list and sub-tuple fields to the input schema:
 
//
// Field names in Schema
//
private const String FIELD1 = "myint";
private const String FIELD2 = "mystring";
private const String FIELD3 = "mydouble";
private const String FIELD4 = "myTupleList"; //add
private const String SUBFIELD1 = "subField1"; //add
private const String SUBFIELD2 = "subField2"; //add

---
The myTupleList field should also be added to the dotnet.sbapp application's 'InputStream1' Input Stream schema. In addition, include myTupleList in the Map Operator's Input Fields so its values can be seen on the application's Output Stream.
---

  4. In the Main method, create the Field object for myTupleList:
 
// turn the field names into Field objects outside the enqueue loop,
// for efficiency of the loop
Schema.Field field1 = schema.GetField(FIELD1);
Schema.Field field2 = schema.GetField(FIELD2);
Schema.Field field3 = schema.GetField(FIELD3);
Schema.Field field4 = schema.GetField(FIELD4); //add

  5. Create a Tuple object for the myTupleList field, and turn sub-field names into field objects:
 
// create a Tuple object for the sub-tuple field,
// and turn sub-field names into field objects
Schema subschema = client.GetSchemaForStream(SUBTUPLE_STREAM);
Tuple subtuple = subschema.CreateTuple();
Schema.Field subfield1 = subschema.GetField(SUBFIELD1);
Schema.Field subfield2 = subschema.GetField(SUBFIELD2);

  6. Create a List object and add the myTupleList field:
 
//create a List object and add the sub-tuple
List<object> myAL = new List<object>();
myAL.Add(subtuple);

  7. Use the Field objects, field4/subfield1/subfield2, to set the values of myTupleList/subField1/subField2 in the enqueue loop:
 
for (int i = 1; i <= NUM_TUPLES; i++) {
// initialize the tuple's fields
tuple.SetInt(field1, i);
tuple.SetString(field2, "Tuple #"+i);
tuple.SetDouble(field3, i / 10.0);
subtuple.SetInt(subfield1, i);
subtuple.SetString(subfield2, "subVal" + i);
tuple.SetList(field4, myAL);

For details on using the SetList() method, refer to the .NET API Help included with your installation of StreamBase.