wandenberg / nginx-push-stream-module

A pure stream http push technology for your Nginx setup. Comet made easy and really scalable.
Other
2.22k stars 295 forks source link

Long-polling won't work #169

Closed softshape closed 9 years ago

softshape commented 9 years ago

Hi all,

after updating to 0.4.1 version I can't make it work.

My nginx configuration -

location /tickets/api/pub {
            push_stream_publisher admin;
            push_stream_channels_path          $arg_id;
            allow  127.0.0.1;
}

location ~ /tickets/api/updates/(.*) {
            push_stream_subscriber                  long-polling;
            push_stream_channels_path          $1;
            push_stream_last_received_message_tag   $arg_tag;
            push_stream_last_received_message_time  $arg_time;
            push_stream_longpolling_connection_ttl  25s;
        }

For tests, I do on the server:

wget http://127.0.0.1/tickets/api/pub?id=12345 --post-data=TEST

It returns:

{"channel": "12345", "published_messages": "0", "stored_messages": "0", "subscribers": "1"}

But to the browser it sends nothing. I listen to /tickets/api/updates/12345 in JavaScript and it's quite. My jQuery code is:

(function poll(){
    $.ajax({ url: "/tickets/api/updates/12345", success: function(data){
        if (data) { console.log(data);  }
    }, timeout: 30000 }).always(function() { poll() });
})();

What can be the problem?

wandenberg commented 9 years ago

Hi @softshape

I see at least two problems here. 1) since you are not saving the messages on server your client will receive only the message published while it is connected. 2) even if you store the messages on server, your client are not sending the lime and tag of the last message received

using your current configuration try to open one console with

curl localhost/tickets/api/updates/12345

and publish a message on another

curl localhost/tickets/api/pub?id=12345 -d test

you will receive the message and be disconnected. This shows that long polling is working. To achieve a proper usage on browser take a look on the examples on documentation. I also recommend to use the pushstream.js if you have problems doing your own client code.