question

Upvotes
Accepted
87 7 13 27

[EMA C++] Can registerClient() & onRefreshMsg() run in different thread?

I develop with EMA C++,

I want to run registerClient()&onRefreshMsg() in different thread so that I can get all chains of HKSE,

shows as pic follows:

are there any methods?

elektronrefinitiv-realtimeelektron-sdkema-apirrtelektron-message-api
icon clock
10 |1500

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

Upvotes
Accepted
25.3k 87 12 25

Hi,

You can not store any EMA owned objects that you receive in the callbacks. As soon as the callback method returns the objects may be destroyed / reused etc by EMA.

You need to extract the field values and store them in application owned objects such as string, int etc. You can then spawn a different thread if required to process the stored values.

It is strongly advised that you minimise the amount of processing performed with the onRefresh / onUpdate callback handlers - since these are executing on the API thread.

As mentioned earlier, many EMA C++ developers consume several thousand instruments - without issues. This off course depends on how often your instruments update and just how CPU intensive your application level processing of the received data is. So I recommend you perform some tests, to see if the data update rates can be handled by your application on the API thread or if you need to spawn another thread to process your data.

icon clock
10 |1500

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

Upvotes
25.3k 87 12 25

Hi @luxiangyuan

You don't need to make all your registerClient() calls from the main() method.

You can call registerClient / unregisterclient from API thread context in which your onRefresh or onUpdate callback methods are invoked - as and when you receive updates to the main chain in those callback methods.

So, when you receive for example the Refresh via the onRefresh and you start to decode & extract the other links in the chain, you can then call registerClient for those additional link.

Likewise, if the chain shrinks some of the chains / underlying RICs are removed from the chain, you can call unregisterClient for those items from the API thread context.

icon clock
10 |1500

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

Upvotes
87 7 13 27

How to invoke the callback methods "onRefresh " or "onUpdate " in new thread?

Is OmmConsumer support multiple thread?

Thank you.

icon clock
10 |1500

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

Upvotes
25.3k 87 12 25

Hi @luxiangyuan

Not sure what you mean about using a new thread / why you want to use a new thread? You can make the registerClient call in the same API thread context on which the onRefreshMsg and onUpdateMsg callbacks are executed.

Many developers writing EMA Consumer applications often subscribe to several thousand instruments using a single OmmConsumer instance...

icon clock
10 |1500

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

Upvotes
87 7 13 27

hi

Now, I receive all the msg I requested in fun onRefreshMsg() or onUpdateMsg()

What I warried about is the "lowefficiency", because I must decode all the msg from HKSE and nasdaq to our struct in the main thread.

I want to store the msg received into a queue at the time onRefreshMsg() or onUpdateMsg() is invoked, then I can decode them with multiple threads but the constructor of refreshMsg and updateMsg is private, so I must decode all the refreshMsg and updateMsg to struct in the main thread, this is why I worried about the "lowefficiency".

icon clock
10 |1500

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

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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