question

Upvotes
Accepted
5 0 0 0

EMAJ: How to keep a long connection in OMMConsumer like 7x24

As subject, my application need to continuously retrieve price from TREP for 7x24.
By referring the reply in a similar question, I tried using Channel and specifying ConnectionPingTimeout, but seems doesn't work, the session still end once after receiving price.

I can't find any similar case in official sample also.

Should I use dead loop or long time thread sleep after registerClient() to keep the connection alive?

Any code or sample for my refer?

Much appreciated for any suggestion!

elektronrefinitiv-realtimeelektron-sdkrrtema-apielektron-message-api
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
Accepted
23k 22 9 14

Hi @loy.longyi,

An EMA Java consumer application can be as long running, as you prefer, and only exit on specific criteria or condition specified by you, such as requested exit.

I suspect that you are asking, because our example consumers that come with Elektron SDK are targeted to 1 minute runs.

The do so by exiting from the main thread, 1 minute after the initial registration similar to this:

 consumer.registerClient(reqMsg.serviceName("ELEKTRON_EDGE").name("IBM.N"), appClient);
 Thread.sleep(60000);

if this is right, you can keep the main thread going any way that is consistent with your requirements, for example

consumer.registerClient(reqMsg.serviceName("ELEKTRON_EDGE").name("IBM.N"), appClient);
while (no_stop_requested == true)
    Thread.sleep(1000)

Please let us know, if this helps, or you are asking about something different, in which case, please be more descriptive on what session end you are referring to?

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Hi Zoya.farberov,

Thank you very much for your reply!

I'm using for loop to keep the thread long running, just like your sample:

consumer.registerClient(reqMsg.serviceName("ELEKTRON_EDGE").name("IBM.N"), appClient);
while (no_stop_requested == true)
    Thread.sleep(1000)

I was worried it's not the official solution. Your clarification helps a lot.

Btw, may I ask if my app has 2 hours break time each day, should I suspend the connection and resume it latter or just end it and create a new one?

Could you pls advise which approach is better?

Thanks in advance!

Upvote
11.5k 16 7 10

Hello @loy.longyi

It is based on your application design and requirement. If you choose to suspend a connection, you can use the API Pause/Resume feature during that 2 hours break. The API will keep a connection with TREP but pause all items subscriptions on that time.

You can find EMA Java Pause/Resume example in EMA Java example 350_MarketPrice_PauseAll example.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Hi Wasin,

Thank you for your reply!

May I ask what scenario should I end and create a new connection instead of using pause/resume?

If my app is suspended for several days, which approach is better for this case?

Thanks in advance!

Upvotes
9.5k 10 5 7

Hello @loy.longyi

In my opinion, if application is suspended for several days, pause/resume may not suitable because item remains open and is still in the ADS Cache. The ADS continues to receive messages from its upstream device (or feed) and updates the item in its cache (but because of the client‟s pause request, does not send new data to the client). For more details, please refer to 3.2.4 Pause and Resume in Elektron API Concepts Guide

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Hi @Pimchaya.Wongrukun,

Got it and thank you for your reply!

I will read the doc in detail.

Click below to post an Idea Post Idea