For a deeper look into our Elektron API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
1 0 1 2

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

websockets
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.

@jan01

Hi,

Thank you for your participation in the forum.

Are any of the replies below satisfactory in resolving your query?

If yes please click the 'Accept' text next to the most appropriate reply. This will guide all community members who have a similar question.

Otherwise please post again offering further insight into your question.

Thanks,

AHS

Please be informed that a reply has been verified as correct in answering the question, and has been marked as such.

Thanks,
AHS

Upvotes
Accepted
22.1k 59 14 21

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.

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.

Upvote
22.1k 59 14 21

Hello @jan01,

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

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
1 0 1 2

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


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
22.1k 59 14 21

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.

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
1 0 1 2

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}]}
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.