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

Two messages per one request #252

Closed LPfan88 closed 7 years ago

LPfan88 commented 7 years ago

Config:

push_stream_store_messages on;
push_stream_message_ttl 10s;

location /pub {
    push_stream_publisher admin;
    push_stream_channels_path $arg_id;
}

location /sub {
    push_stream_subscriber long-polling;
    push_stream_channels_path $arg_id;
    push_stream_longpolling_connection_ttl 25s;
}

I sent two messages one by one (first: {"type":"unread_count"}, second: {"type":"new_message"}). Response at /sub:

{"type":"unread_count"}{"type":"new_message"}

Two messages together. Is this expected behaviour? I want to receive only one message per request. How can i do this? Thanks.

wandenberg commented 7 years ago

If you are connected on the server and then send the messages you should receive only one message, be disconnected and then you have to connect again to receive the other one. Every time you connect to the server using long-polling you have to inform what was the latest received message (check the examples). If there is more than one message stored on the server you will receive all together, there isn't a way to receive one by one, this is an optimisation of the long-polling "protocol". Because of that your messages should be wrapped in to make a valid JSON. Take a look on the readme examples, there is a configuration on how to do this using long-polling. These wrappers aren't done by default because you can deliver any type of message, not necessarily JSON.

LPfan88 commented 7 years ago

Ok I understood. Thanks!