use push_stream_store_messages but still loss message

123 views
Skip to first unread message

賴宏

unread,
Jun 23, 2015, 7:10:32 AM6/23/15
to nginxpu...@googlegroups.com
Hi,
I am trying to get store message by adding If-None-Match and If-Modified-Since in http request header.
However, when I send messages fast in a short time, there are some messages missing.
Please see my settings below. Is there something wrong?

----------------------------------------------------------
nginx.conf
----------------------------------------------------------
push_stream_shared_memory_size 512M;
push_stream_channel_inactivity_time 30s;
push_stream_message_ttl 10s;
push_stream_max_messages_stored_per_channel 1024;

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

location ~ /sub/(.*) {
default_type text/plain;

set $channel_id $1;
access_by_lua_file push_stream_access.lua;
push_stream_subscriber long-polling;
push_stream_channels_path $1;
push_stream_authorized_channels_only off;
push_stream_longpolling_connection_ttl 30s;
push_stream_last_received_message_tag $arg_tag;
push_stream_last_received_message_time $arg_time;
push_stream_message_template "{\"m\":\"~text~\",\"e\":~tag~,\"t\":\"~time~\"}";
}

----------------------------------------------------------
push_stream_access.lua
----------------------------------------------------------
-- Get Parameter
local last_modified = ngx.req.get_uri_args()["t"]
local etag = ngx.req.get_uri_args()["e"]

-- Set Request Header
ngx.req.set_header("If-None-Match", etag)
ngx.req.set_header("If-Modified-Since", last_modified)

----------------------------------------------------------
pub.sh
----------------------------------------------------------
#!/bin/bash

i="0"

while [ $i -lt 100 ]
do
        curl -X POST "http://127.0.0.1/pub?id=demo" -d "Hello$i"
        i=$[$i+1]
        sleep 0.01
done

----------------------------------------------------------
long-poll.htm
----------------------------------------------------------
<html>
        <head>
                <title>Long Polling</title>
                <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
                <script>
                        $(function() {
                                var last_modified = 'Thu, 1 Jan 1970 00:00:00 GMT';
                                var etag = 0;

                                function poll() {
                                        $.ajax({
                                                url: 'http://127.0.0.1/sub/wb.1_1?t=' + last_modified + '&e=' + etag,
                                                cache: false,
                                                timeout: 10000,
                                                dataType: 'json',
                                                success: function(data) {
                                                        message = data.m;
                                                        etag = data.e;
                                                        last_modified = data.t;

                                                        $("#lp_text").val(message + "\n" + $("#lp_text").val());

                                                        console.log(data);
                                                        poll();
                                                },
                                        });
                                }

                                poll();
                        });
                </script>
        </head>
        <body>
        <textarea id="lp_text" style="width: 600px; height: 800px;"></textarea>
        </body>
</html>

Wandenberg Peixoto

unread,
Jun 23, 2015, 12:50:17 PM6/23/15
to nginxpu...@googlegroups.com
Hi,

If you set the directives push_stream_last_received_message_tag $arg_tag; and push_stream_last_received_message_time $arg_time; , the module will look for the values using the query string parameters time and tag.

you have to choose...
Or change this directives to use the arguments "t" and "e", changing $arg_time by $arg_t and $arg_tag by $arg_e and remove your 
access_by_lua_file push_stream_access.lua; filter.
Or remove the configuration of push_stream_last_received_message_tag and push_stream_last_received_message_time.

I suggest to do the first, less complicated and less code on server.
The client code seems OK.

Regards,
Wandenberg



--
You received this message because you are subscribed to the Google Groups "nginxpushstream" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nginxpushstre...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages