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
i=$[$i+1]
sleep 0.01
done
----------------------------------------------------------
long-poll.htm
----------------------------------------------------------
<html>
<head>
<title>Long Polling</title>
<script>
$(function() {
var last_modified = 'Thu, 1 Jan 1970 00:00:00 GMT';
var etag = 0;
function poll() {
$.ajax({
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>