Как из long-polling канала прочитать только последнее сообщение?

При реализации простейшего обмена сообщениями через long-polling с помощью nginx возникла проблема: в XMLHttpRequest.responseText приходят все сообщения, которые были отправлены в этот канал, а не одно. Не думаю, что так и должно быть.
Получение сообщений (js):
var xhr = new XMLHttpRequest();
xhr.open('GET', '/sub/' + subID, true);
xhr.send();
xhr.onreadystatechange = xhr.onload = function () {
if (xhr.status == 200) {
       console.log(xhr.responseText);
}
}


Отсюда вопрос: проблема в конфигурации модуля nginx, или в чем-то еще?
Отправка сообщения:
$channel_id = '1';
$msg = array('text' => 'a');

$ch = curl_init('http://127.0.0.1/pub?id='.$channel_id);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($msg));
if (curl_exec($ch)) 
	echo 'sended '.json_encode($msg);
else 
	echo 'fail';
curl_close($ch);


NGINX:
location / {
            location ~ /sub/(.*) {
                # activate subscriber (streaming) mode for this location
                push_stream_subscriber;

                # positional channel path
                push_stream_channels_path                 $1;
                push_stream_longpolling_connection_ttl    30s;
                push_stream_last_received_message_time    $arg_time; 
                push_stream_last_received_message_tag     $arg_tag;
            }
            location /pub {
               # activate publisher (admin) mode for this location
               push_stream_publisher admin; 
                # query string based channel id
                push_stream_channels_path               $arg_id;
            }
            location /channels-stats {
                # activate channels statistics mode for this location
                push_stream_channels_statistics;

                # query string based channel id
                push_stream_channels_path               $arg_id;
            }
  • Вопрос задан
  • 307 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы