Is it possible for a LS web client to connect to multiple LS servers for different data resources? Is there any sample code I can reference to? Thanks
Is it possible for a LS web client to connect to multiple LS servers for different data resources? Is there any sample code I can reference to? Thanks
Hi,
currently it is not supported, but that's something that will be released with the next version of html client: I'm working on it.
As per now your only chance is to isolate two applications in two different iframes and connect each one to a different server
Can you provide any sample code? Thanks
I mean something as simple as this:
where you have two separate pages, each one connecting to a different server: in my case the first one connects to push50.lightstreamer.com while the second one connects to push51.lightstreamer.com (in this case it's actually the same server, but the browser doesn't know that)
HTH
Does the latest version of LS web client support multiple connections to difference LS servers for different data resources?
Sorry for not following up on this, anyway the answer is yes, you can now create as many LightstreamerClient instances as needed and connect them to different servers
Is it backward compatible with LS 4.0 server?
Newer Lightstreamer servers support older clients while older servers usually do not support newer clients; In this case you can't use the new JS client with the old server.
Anyway please note that upgrading from server 4 to server 5 is not a long process; Check the readme and the changelog compatibility notes for details.
Hi, how would this look like using this example - https://github.com/Lightstreamer/Lig...r/src/index.js, assuming we need the same client session to connect to two server hosts for the same subscription at the same time. Is it possible to have an example?
I was reading the documentation, but couldn't find a clear solution. Thanks in advance!
Each Lightstreamer client session is reserved for a "host/Adapter Set" pair.
So if you need to connect your client application to two different hosts you need also two different client sessions, ie. instantiate two LightstreamerClient objects and connect them to the different hosts.
Regards,
Giuseppe
Thanks for the reply, I have one more question. When subscribing to the same item through these two LS clients during the same user session, in the logs I am seeing always one or the other host giving updates. Is that expected behavior? I was hoping to receive one update at a time from both hosts. The only thing I changed from that Demo sample is instantiating a new LS object and call the other methods for each LS client. I am using the SimpleLogAppender to log client listener updates. I am new to this, so trying to understand if there is something between the listener or the logger that doesn't allow it differently, or is it me who is taking the wrong approach. Thanks!
e.g Logs
host1 - Connected:Streaming
host2 - Connected:Streaming
host1
subscribed
item update
item update
item update
host2
subscribed
item update
item update
item update
Why somewhere here there isn't:
host1
item update
host2
item update
Hi sdi0900,
I am not sure if that could be a server-side issue or related to the client.
But just to avoid misunderstanding please take a look at this example changed to get the same real-time data form two different Adapter Set.
Please confirm that your version is something very similar.Code:var ls = require('lightstreamer-client-node');
var myClient = new ls.LightstreamerClient("https://push.lightstreamer.com","WELCOME");
myClient.addListener({
onStatusChange: function(newStatus) {
console.log(newStatus);
}
});
myClient.connect();
var mySnd = new ls.LightstreamerClient("https://push.lightstreamer.com","DEMO");
mySnd.addListener({
onStatusChange: function(newStatus) {
console.log(newStatus);
}
});
mySnd.connect();
var mySubscription = new ls.Subscription("MERGE",["item1","item2","item3"],["stock_name","last_price"]);
mySubscription.setDataAdapter("STOCKS");
mySubscription.setRequestedSnapshot("yes");
mySubscription.addListener({
onSubscription: function() {
console.log("SUBSCRIBED");
},
onUnsubscription: function() {
console.log("UNSUBSCRIBED");
},
onItemUpdate: function(obj) {
console.log("Fst - " + obj.getValue("stock_name") + ": " + obj.getValue("last_price"));
}
});
myClient.subscribe(mySubscription);
var my2S = new ls.Subscription("MERGE",["item1","item2","item3"],["stock_name","last_price"]);
my2S.setDataAdapter("QUOTE_ADAPTER");
my2S.setRequestedSnapshot("yes");
my2S.addListener({
onSubscription: function() {
console.log("SUBSCRIBED");
},
onUnsubscription: function() {
console.log("UNSUBSCRIBED");
},
onItemUpdate: function(obj) {
console.log("Snd - " + obj.getValue("stock_name") + ": " + obj.getValue("last_price"));
}
});
mySnd.subscribe(my2S);
Thank you,
Giuseppe
Hi, this is pretty much what I am doing, unfortunately I can't test it out with the Demo sample, but if you can take a look and let me know if this seems straightforward to you would be helpful! The reason I am following this approach is to not duplicate so much code.
Quote:
varls = require('lightstreamer-client-node');
constconnect = (url, adapter) => {
const lsClient = new ls.LightstreamerClient(url, adapter);
lsClient.addListener({
onStatusChange: (newStatus) => {
console.log(newStatus)
},
});
lsClient.connect();
return lsClient;
};
var myClient1 = connect("https://push.lightstreamer1.com","WELCOME");
var myClient2 = connect("https://push.lightstreamer2.com", "WELCOME")
const lsSubscribe = (lsClient) => {
var mySubscription = new ls.Subscription("MERGE",["item1","item2","item3"],["stock_name","last_price"]);
mySubscription.setDataAdapter("STOCKS");
mySubscription.setRequestedSnapshot("yes");
mySubscription.addListener({
onSubscription: function() {
console.log("SUBSCRIBED");
},
onUnsubscription: function() {
console.log("UNSUBSCRIBED");
},
onItemUpdate: function(obj) {
console.log("Fst - " + obj.getValue("stock_name") + ": " + obj.getValue("last_price"));
}
});
lsClient.subscribe(mySubscription);
};
lsSubscribe(myClient1)
lsSubscribe(myClient2)
Your code looks absolutely correct to me.
I just made a couple of minor changes:
and testing it works fine, this is my output:Code:var myClient1 = connect("http://localhost:8080","WELCOME");
var myClient2 = connect("http://localhost:8080", "WELCOME")
const lsSubscribe = (lsClient, prefix) => {
console.log(prefix + " - " + obj.getValue("stock_name") + ": " + obj.getValue("last_price"));
lsSubscribe(myClient1, "1")
lsSubscribe(myClient2, "2")
the first 3 updates for each client are the snapshot, and it makes sense that they come in bulk for the two clients, then there is the alternation.Code:CONNECTING
CONNECTING
CONNECTED:STREAM-SENSING
CONNECTED:STREAM-SENSING
CONNECTED:WS-STREAMING
CONNECTED:WS-STREAMING
SUBSCRIBED
SUBSCRIBED
1 - Anduct: 2.93
1 - Bagies Consulting: 7.24
1 - Ations Europe: 15.98
2 - Anduct: 2.93
2 - Bagies Consulting: 7.24
2 - Ations Europe: 15.98
2 - Ations Europe: 16.04
1 - Ations Europe: 16.04
2 - Ations Europe: 15.9
1 - Ations Europe: 15.9
2 - Ations Europe: 15.77
1 - Ations Europe: 15.77
1 - Ations Europe: 15.89
2 - Ations Europe: 15.89
1 - Ations Europe: 16.01
2 - Ations Europe: 16.01
1 - Bagies Consulting: 7.19
2 - Bagies Consulting: 7.19
2 - Ations Europe: 16.09
1 - Ations Europe: 16.09
2 - Ations Europe: 16.03
1 - Ations Europe: 16.03
1 - Ations Europe: 16.12
2 - Ations Europe: 16.12
2 - Ations Europe: 15.98
1 - Ations Europe: 15.98
Did you expect something different?
Regards,
Giuseppe
Ciao Giuseppe, thank you so much for testing it, this is what I was expecting, but with my setup I don't get the same results. I need to check further, just wasn't sure if my code did what I wanted to, so thanks to you now I do!