What is the best way to maintain websocket connection?

Hello,

I am trying to publish data to Elektron's websocket. Authorization token only lives for 10 minutes and when it expires, session is being closed. Before session expires I would like to start new session using refresh token. Once new session is ready my system would switch over to it and close previous session.


With this approach i am experiencing a bit inconsistent behaviour from the system. Sometimes when I issue login request for second session - first one gets closed.

I am attaching diagram of experienced behaviour.


session-extendingdrawio-1.png


I would appreciate any hints on how can I maintain websocket in such way so my system always have at least one active connection to publish data.


Regards,

Jan Roman

Tagged:

Best Answer

  • Gurpreet
    Gurpreet admin
    Answer ✓

    Hi @jan01,

    Your login message when you are refreshing the token is incorrect. I would encourage you to take a look at how this is implemented in the python sample provided in the tutorial.

Answers

  • Hello @jan01,

    Can you please elaborate on how you are trying to publish the data. Are you using Refinitiv Contributions Channel?

  • jan01
    jan01 Newcomer

    Hi Gurpeet,

    Thanks for getting back. Yeah I am using Refinitiv Contributions Channel using websocket connection to your cloud instance. For now I am using preproduction environment at endpoint: wss://contrib-ws1-emea1.uat.platform.refinitiv.com/WebSocket

    I am using OAuth endpoint: https://api.ppe.refinitiv.com/auth/oauth2/v1/token

    Regards,

    Jan


  • Ok, in that case, you don't need to start a new websocket session. When the auth token is about to expire, you can proactively renew a new token and send it to the server. This way your existing connection will not be terminated.

    See the python tutorial and associated example here.

  • jan01
    jan01 Newcomer

    Hello @Gurpreet

    I was trying this approach but it did not work for me. Please have a look on extract from logs my end. I am getting "Reauthorisation message error" when i try to extend session using refresh token.

    Regards,

    Jan

    Dec 13, 2021 11:13:51 PM cf.idx.v3.shared.V3 log
    INFO: {msg=sending message, RefinitivSession=1, messageToSend={"ID":1,"Domain":"Login","Key":{"NameType":"AuthnToken","Elements":{"ApplicationId":"MY-LOGIN","Position":"12345","AuthenticationToken":"INITIAL-AUTHORIZATION-TOKEN"}}}}
    Dec 13, 2021 11:13:53 PM cf.idx.v3.shared.V3 log
    INFO: {msg=processMessage, RefinitivSession=1, messageReceived=[{"ID":1,"Type":"Refresh","Domain":"Login","Key":{"Name":"MY-LOGIN","Elements":{"TRCE:MaxMessagesPerSecond":1000}},"State":{"Stream":"Open","Data":"Ok","Text":"Login accepted by host aa2bdb1c1b4b via ip-10-28-169-77.eu-west-1.compute.internal"},"ClearCache":false,"DoNotCache":true,"Private":true,"Solicited":false}]}
    ...
    Dec 13, 2021 11:14:11 PM cf.idx.v3.shared.V3 log
    INFO: {msg=processMessage, RefinitivSession=1, messageReceived=[{"Type":"Ping"}]}
    Dec 13, 2021 11:14:11 PM cf.idx.v3.shared.V3 log
    INFO: {msg=sending message, RefinitivSession=1, messageToSend=[{"Type":"Pong"}]}
    ...
    Dec 13, 2021 11:15:02 PM cf.idx.v3.shared.V3 log
    INFO: {msg=sending message, RefinitivSession=1, messageToSend={"ID":1,"Domain":"Login","Key":{"NameType":"AuthnToken","Elements":{"ApplicationId":"MY-LOGIN","Position":"12345","AuthenticationToken":"MY REFRESH TOKEN"}}}}
    Dec 13, 2021 11:15:02 PM cf.idx.v3.shared.V3 log
    INFO: {msg=processMessage, RefinitivSession=1, messageReceived=[{"ID":1,"Type":"Status","Domain":"Login","State":{"Stream":"Closed","Data":"Suspect","Code":"NotEntitled","Text":"Reauthorisation message error"},"Private":true}]}