Article

Enterprise Messaging API (Java) - Batch and View features

    Chavalit Jintamalit
    Developer Advocate

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.

 

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:

Here is the sample response:

 

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:

Here is the sample response:

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.

Here is the sample response:

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.refinitiv.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.