OmmConsumer token refresh using Java SDK

Client's query:

I understand that you use Oauth and how that works. But we are using your Java SDK and use a OmmConsumer. As I understand it the OmmConsumer should handle that. And I find no documentation on how to make a OmmConsumer refresh it’s login.

So my actual question is how do we keep our OmmConsumer fresh. Do we need to listen to some event and create a new OmmConsumer to keep getting data? How long can we expect an OmmConsumer to be alive? Do you have any documentation on how to keep an OmmConsumer alive?

The failure we got last week clearly stated (“ Closed/Suspect/Timeout - text: "Authentication failure time has been exceeded."”) that we had a timeout in our session. We are not in service during night and the service it restarted now and then. This could be the reason we don’t timeout that often. We could restart the service every night but what is the correct way of handle a OmmConsumer that we would like to keep alive?

Best Answer

Answers

  • Hi @Mikee Espinosa

    Ordinarily, you should not need to refresh the token, the RT-SDK should be taking care of it.

    The above sounds like an exceptional scenario e.g. there could have been some maintenance on the RTO or Authentication service and the application was disconnected and/or the API was not able to refresh the token.

    You can monitor the Login stream to confirm if you are logged or have been logged out e.g.

    How can I capture the ERROR message reactorChannelEventCallback - Forum | Refinitiv Developer Community

    In summary, if you want to know the state of connectivity to a server within the application, you can manually register for the Login Domain stream.

    Please refer to the 330__Login__Streaming example that comes with the SDK.

    So, for example, if the DataState of your Login stream changes to Suspect, you know something is not right - but as long as the StreamState remains open - this should recover to DataState of OK. If however, it has not recovered after a while, you could try and reconnect.

    OR, If the StreamState changes to Closed - as appears to be the case in your original post, then this indicates that the application has been logged out of the server and you would need to reconnect.
    The OmmConsumer represents the session/connection to the server -


  • Client's response below:

    The examples you are referring to seems to no longer exists. Can you point out where they are on github?

    https://github.com/Refinitiv/Real-Time-SDK/tree/master/Java

    If you could answer this more specific question if would be great. Our setup is that we have a service class that implements OmmConsumerClient interface. An instance of the class is injected with an instance of a OmmConsumer. How can we in the class register for the login events? Would this be the correct way?

    consumer.registerClient(EmaFactory.createReqMsg().domainType(EmaRdm.MMT_LOGIN), this);

    If we get disconnected, would that then raise events to onRefreshMsg or onStatusMsg? Can you point to an example of what such an event would look like?

  • Hi @Mikee Espinosa @Michael Ronald Cortez.Espinosa

    The 330 example mentioned is present in the RT-SDK download package and on Github : Real-Time-SDK/Java/Ema/Examples/src/main/java/com/refinitiv/ema/examples/training/consumer/series300/ex330_Login_Streaming at master · Refinitiv/Real-Time-SDK (github.com)

    If disconnected, you should get a StatusMsg - as mentioned in the other post, for the purpose of disconnect detection, you monitor StatusMsg for the Login domain (not for market data items).

    A Login Domain RefreshMsg is received when you are successfully logged in.

    The above example registers for the Login stream implicitly by specifying an appClient when it creates the OmmConsumer:

    consumer  = EmaFactory.createOmmConsumer(EmaFactory.createOmmConsumerConfig().host("localhost:14002").username("user"), appClient); 

    For a more explicit example, please refer to the 333 example Real-Time-SDK/Java/Ema/Examples/src/main/java/com/refinitiv/ema/examples/training/consumer/series300/ex333_Login_Streaming_DomainRep at master · Refinitiv/Real-Time-SDK (github.com) which includes the following:

    LoginReq loginReq = EmaFactory.Domain.createLoginReq();
    consumer.registerClient(loginReq.message(), appClient);
  • Client's response:

    Thanks for pointing out the examples, not easy to find.

    We seem to get login related events now, thanks for that.

    I have some related questions:

    • For network-issues, it seems like the consumer automatically tries to reconnect? I.e. if network goes down, and then up, the consumer automatically reconnects? Is this correct? Is there any documentation of this behaviour? (Sorry if I missed something obvious.)
    • For the problem Johan originally reported (State: Closed/Suspect/Timeout - text: "Authentication failure time has been exceeded.") – would the consumer automatically reconnect when the server was available, or was a restart of the service needed?
    • Regarding the token auth; my question was really how our consumer can be configured to catch what the loggerMsg logs as an event? Is there a domain to register a client for ReqMsg, or something else?
  • Hi @Michael Ronald Cortez.Espinosa

    • RT-SDK has certain reconnect / item recovery functionality built-in - you can find some information in the API_ConceptsGuide.pdf as well as the ETAJ_DevGuide.pdf. You can also read about the various related parameters in the EMAJ_ConfigGuide
    • The Closed Stream state means you have been logged out of the server and therefore you would need to manually try and login in again i.e. by recreating your OmmConsumer - which represents the session to the server and also includes the Login process (behind the scenes)
    • Rather than trying to catch LoggerMsg which can potentially change, you need to catch the Closed Login stream and then try and reconnect when you are logged out - as described in my earlier responses.


  • Hi @umer.nalla , I can't open the PDF file.
  • Hi @Michael Ronald Cortez.Espinosa

    Can you download the RT-SDK from Github or the Developer Portal Download pages? If so, the above documents are included in the ETA\Docs and EMA\Docs folders of the RT-SDK packages - if you don't already have them.

    You can also access them from the relevant subfolders of the RT-SDK Java repository on GitHub

  • Regarding this:

    3. Regarding the token auth; my question was really how our consumer can be configured to catch what the loggerMsg logs as an event? Is there a domain to register a client for ReqMsg, or something else?

    Comment: Rather than trying to catch LoggerMsg which can potentially change, you need to catch the Closed Login stream and then try and reconnect when you are logged out - as described in my earlier responses.

    Yes, that was what I was trying to explain what we want. But when trying to test this it seems like the “invalid_grant” error is NOT appearing as a Login stream event. But you mean that when the “invalid_grant” happens, it should also show up as a Login stream event? Is it possible to double check that that is how it works?

  • Hi @Michael Ronald Cortez.Espinosa

    Apologies for any misunderstanding.

    In your initial and subsequent post you mentioned ' (“ Closed/Suspect/Timeout - text: "Authentication failure time has been exceeded."”) - can you confirm which domain are you receiving this for - if not the Login domain?

    You have not previously mentioned the 'invalid_grant' message - can you please advise when and where you see this? Do you have a fuller console or log output for this? You mention that you are testing this - please advise how you are testing this - are frequently experiencing the 'Closed/Suspect/Timeout ' scenario?

    Having stated the above - based on what you have said so far, I suspect that this issue requires a deeper offline investigation - beyond what is possible on a forum.

    If you log in to the Developer Portal and navigate to Refinitiv Real-Time Java SDK | Refinitiv Developers - you should see a Contact Premium Support button. Please use that to raise a ticket with the Developer support team - who can help you diagnose 1657878704024.png

  • Response from the client:


    In addition to the below, we also sometimes get this loggerMsg:

    ClientName: ChannelCallbackClient

    Severity: Warning

    Text: Received Channel warning event on channel Channel_1

    Instance Name Consumer_1_1

    RsslReactor @78e0aa5a

    RsslChannel @48e09fc9

    Error Id 0

    Internal sysError 0

    Error Location Reactor.processWorkerEvent

    Error text Failed REST request for the token service from HTTP status code 400 for user: GE-A-00920365-3-9187. Text: {"error":"invalid_grant"}

    Some questions:

    • Can you explain when this occurs?
    • Can this be seen via consumer events as well? What EmaRdm domain type should be registered to receive this event?