Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15
  1. #11
    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

  2. #12
    Administrator
    Join Date
    Feb 2012
    Location
    Milano
    Posts
    716
    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.

    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);
    Please confirm that your version is something very similar.

    Thank you,
    Giuseppe

  3. #13
    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.
    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)
    Last edited by sdi0900; November 24th, 2020 at 12:49 AM.

  4. #14
    Administrator
    Join Date
    Feb 2012
    Location
    Milano
    Posts
    716
    Your code looks absolutely correct to me.
    I just made a couple of minor changes:

    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")
    and testing it works fine, this is my output:
    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
    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.
    Did you expect something different?

    Regards,
    Giuseppe

  5. #15
    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!

 

 

Similar Threads

  1. How to use multiple adapters in one web client
    By sjohn in forum Client SDKs
    Replies: 11
    Last Post: January 23rd, 2015, 12:22 PM
  2. Single data provider and multiple data sources
    By pluczak in forum Adapter SDKs
    Replies: 1
    Last Post: April 26th, 2012, 11:50 AM
  3. .NET Client Multiple Subscriptions
    By wwatts in forum Client SDKs
    Replies: 4
    Last Post: February 16th, 2010, 09:58 AM
  4. Deploying Demos in different servers
    By sarbao in forum Adapter SDKs
    Replies: 1
    Last Post: April 20th, 2009, 10:29 AM
  5. Replies: 3
    Last Post: February 8th, 2007, 10:11 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT +1. The time now is 12:54 PM.