Enterprise Messaging API - Batch and View feature combined
Introduction
Enterprise Messaging API comes with sample code for batch request(example 370) and view request(example 360).
However, this article will walk through how to combine both batch and view feature in the same request message to request multiple items at a time and to limit the data fields received.
Dependency on ADS
For TREP 2.X, Batch and View features required a premium license in ADS. Please contact your Customer Success Manager (CSM) to confirm your license type.
For TREP 3.X and higher Batch and View features are included and do not need an additional license.
Batch Feature
A consumer can request many items with a single client-based request called a Batch request.
The consumer provides a handful of item names in a single request to ADS/Elektron.
The ADS then sends the items as if they were opened individually so they can be managed as individual items.
In the example below, the client makes a single batch request for "JPY=", "TRI.N" and "0005.HK".
Here is the sample code represents the same Batch request:
//Prepare multiple RICs in an OmmArray
OmmArray array = EmaFactory.createOmmArray();
array.add(EmaFactory.createOmmArrayEntry().ascii("JPY="));
array.add(EmaFactory.createOmmArrayEntry().ascii("TRI.N"));
array.add(EmaFactory.createOmmArrayEntry().ascii("0005.HK"));
ElementList batchView = EmaFactory.createElementList();
batch.add(EmaFactory.createElementEntry().array(EmaRdm.ENAME_BATCH_ITEM_LIST, array));
//Register a Request Message and add Batch Request to the Request Payload
consumer.registerClient(EmaFactory.createReqMsg().serviceName("ELEKTRON_DD").payload(batch), appClient);
Here is the sample response:
Item Name: JPY=
Service Name: ELEKTRON_DD
Item State: Open / Ok / None / 'All is well'
Fid: 1 Name = PROD_PERM DataType: UInt Value: 213
Fid: 2 Name = RDNDISPLAY DataType: UInt Value: 153
...
...
...
Fid: 14202 Name = MIDLO1_MS DataType: Time Value: 15:22:47:361
Fid: 14208 Name = BID_HR_MS DataType: Time Value: 17:0:0:862
Item Name: TRI.N
Service Name: ELEKTRON_DD
Item State: Open / Ok / None / 'All is well'
Fid: 1 Name = PROD_PERM DataType: UInt Value: 6562 Fid: 2 Name = RDNDISPLAY DataType: UInt Value: 64
...
...
...
Fid: 32741 Name = TRNOVR_UNS DataType: Real Value: 1.102858114E7
Fid: 32743 Name = ACVOL_UNS DataType: UInt Value: 241191
Item Name: 0005.HK
Service Name: ELEKTRON_DD
Item State: Open / Ok / None / 'All is well'
Fid: 1 Name = PROD_PERM DataType: UInt Value: 4945
Fid: 2 Name = RDNDISPLAY DataType: UInt Value: 62
...
...
...
Fid: 32741 Name = TRNOVR_UNS DataType: Real Value: 1.528571383988E9
Fid: 32743 Name = ACVOL_UNS DataType: UInt Value: 22435246
View Feature
Using a view, a consumer requests a subset of fields with a client-based item request.
The consumer specifies a set of fields in a request to the ADS.
When the ADS receives the requested fields, it sends the subset back to the consumer.
In the example below, the client makes a View request for "BID"(Field ID 22) and "ASK"(Field ID 25) fields for JPY=.
Here is the sample code represents the same View request:
//Prepare multiple field IDs in an OmmArray
OmmArray array = EmaFactory.createOmmArray(); array.fixedWidth(2);
//Setting fixed-width of each array entry size, this is not a number of entry.
array.add(EmaFactory.createOmmArrayEntry().intValue(22));//FID22 for BID
array.add(EmaFactory.createOmmArrayEntry().intValue(25));//FID25 for ASK
ElementList view = EmaFactory.createElementList();
view.add(EmaFactory.createElementEntry().uintValue(EmaRdm.ENAME_VIEW_TYPE, 1));
view.add(EmaFactory.createElementEntry().array(EmaRdm.ENAME_VIEW_DATA, array));
//Register a Request Message and add Batch Request to the Request Payload
consumer.registerClient(EmaFactory.createReqMsg().serviceName("ELEKTRON_DD").name("JPY=")
.payload(view), appClient);
Here is the sample response:
Item Name: JPY=
Service Name: ELEKTRON_DD
Item State: Open / Ok / None / 'All is well'
Fid: 22 Name = BID DataType: Real Value: 112.79
Fid: 25 Name = ASK DataType: Real Value: 112.8
Batch and View Features combined
The consumer application can also use Batch and View features combined.
The consumer can specify a set of fields in a request to the ADS using View feature.
The consumer can also specify a set of items in a request to the ADS. using Batch feature.
In the example below, the client makes a single batch request for "JPY=", "TRI.N" and "0005.HK" and requesting for "BID" and "ASK" fields.
//Prepare multiple field IDs in an OmmArray
OmmArray array = EmaFactory.createOmmArray();
array.fixedWidth(2);
//Setting fixed-width of each array entry size, this is not a number of entry.
array.add(EmaFactory.createOmmArrayEntry().intValue(22));//FID22 for BID
array.add(EmaFactory.createOmmArrayEntry().intValue(25));//FID25 for ASK
//Prepare multiple RICs in an OmmArray
OmmArray arrayI = EmaFactory.createOmmArray();
arrayI.add(EmaFactory.createOmmArrayEntry().ascii("JPY="));
arrayI.add(EmaFactory.createOmmArrayEntry().ascii("TRI.N"));
arrayI.add(EmaFactory.createOmmArrayEntry().ascii("0005.HK"));
//Combine both Batch and View and add them to ElementList
ElementList batchView = EmaFactory.createElementList();
batchView.add(EmaFactory.createElementEntry().array(EmaRdm.ENAME_BATCH_ITEM_LIST, arrayI));
batchView.add(EmaFactory.createElementEntry().uintValue(EmaRdm.ENAME_VIEW_TYPE, 1));
batchView.add(EmaFactory.createElementEntry().array(EmaRdm.ENAME_VIEW_DATA, array));
//Register a Request Message and add Batch and View Request to the request payload
consumer.registerClient(EmaFactory.createReqMsg().serviceName("ELEKTRON_DD").payload(batchView), appClient);
Here is the sample response:
Item Name: JPY= (Handle = 2)
Service Name: ELEKTRON_DD
Item State: Open / Ok / None / 'All is well'
Fid: 22 Name = BID DataType: Real Value: 112.78
Fid: 25 Name = ASK DataType: Real Value: 112.81
Item Name: TRI.N (Handle = 3)
Service Name: ELEKTRON_DD
Item State: Open / Ok / None / 'All is well'
Fid: 22 Name = BID DataType: Real Value: 45.55
Fid: 25 Name = ASK DataType: Real Value: 45.56
Item Name: 0005.HK (Handle = 4)
Service Name: ELEKTRON_DD
Item State: Open / Ok / None / 'All is well'
Fid: 22 Name = BID DataType: Real Value: 68.05
Fid: 25 Name = ASK DataType: Real Value: 68.1
The response message is a subset of all available fields. All three instruments receive their own handle which can be used to individually control these streams.
Sample consumer code using Enterprise Messaging API (Java)
See the attached source code for a sample Java class.
The minimal code in the sample demonstrates the core functionality only.
The sample Java class connects to ADS and then sends request message which is hardcoded instruments and fields using Batch and View features.
The response is extracted and is printed out to the console output.
To run the sample:
1. Download the attached source code and extract it to "com.thomsonreuters.ema.examples.training.consumer.series300.example375__MarketPrice__BatchView" package.
2. Modify ADS IP address, ADS Port, DACS user and Service Name in the sample code.
3. Run the example and observe the console output
From the sample output:
The first message is for the batch request. So your application receives Item State as "Closed" with "Stream closed for batch".
In this case, it is a batch request for JPY=, 0005.HK and TRI.N RICs.
So your application receives 3 more streams for JPY=, 0005.HK and TRI.N accordingly.