EMA Java : Batch Request - How to detect if the response message is fully completed

I am interested to use EMA Batch Request to get the fields for a list of contracts

e.g. from EMA example370__MarketPrice__Batch consumer.registerClient(EmaFactory.createReqMsg().serviceName("REUTERS_DEV").payload(batch), appClient);

Thread.sleep(60000);// API calls onRefreshMsg(), onUpdateMsg() and onStatusMsg()

1) How can I listen to snapshot data only (no update)?

2) The examples use a thread.sleep((60000) after sending the request. How to determine how long it should sleep ?

3) How can I know if the fields of all Rics are returned ?

Best Answer

  • Hi @OX

    1. Yes, if you’re only interested in snapshot data (no updates)
      you should disable updates with .interestAfterRefresh(false).
    2. Waiting for a period of time is ok for an example but is not
      a solution for a production application. Indeed, you cannot tell in advance how
      long it will take to open all your RICs. Because of that there’s a risk that
      either you do not wait long enough (and you miss some RICs) or you wait
      unnecessarily too long.
    3. As far as I know EMA doesn’t tell you when all
      the item streams of your batch request are complete. I’m afraid that you will have
      to preserve the status of each individual item (RICs) in order to understand if the batch request is complete or not. For every RIC that you requested in the
      batch EMA will open a new item stream and send either:
      - a Refresh message that
      contains the whole list of fields of the item
      or
      - a Status message that potentially indicates a closed stream state and contains an error message.
      Once you received either a Refresh message or a Status message
      for all the RICs you requested, you know that you batch request is complete.

Answers

  • Hi @OX

    1. The ".interestAfterRefresh(false)" will let the application consumes data as a non-streaming (snapshot). The application will get only "refresh" data to the onRefreshMsg callback function and does not get any updates data.
    2. You can use the "user dispatch" mode which lets the application thread controls and manages all callbacks execute. Please see an example in EMA Java's example130_MarketPrice_UserDisp application
    3. The refresh data comes to application's onRefreshMsg always contains all fields data from TREP/Elektron (if the application uses View feature, it will contains all requested fields data)

    Please see an example code from example130 below:

    consumer  = EmaFactory.createOmmConsumer(EmaFactory.createOmmConsumerConfig()
    .operationModel(OperationModel.USER_DISPATCH)
    .host("localhost:14002").username("user"));

    consumer.registerClient(EmaFactory.createReqMsg().serviceName("DIRECT_FEED").name("IBM.N"), appClient, 0);

    long startTime = System.currentTimeMillis();
    while (startTime + 60000 > System.currentTimeMillis()) //The application controls how long for dispatching incoming events here
    consumer.dispatch(10); // calls to onRefreshMsg(), onUpdateMsg(), or onStatusMsg() execute on this thread