From 44f599747e0b1e636ca45016135f4319602bf52b Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Fri, 13 Mar 2020 17:30:31 -0700 Subject: [PATCH] (cobra client) ws cobra subscribe resubscribe at latest position after being disconnected --- docs/CHANGELOG.md | 4 ++++ ixwebsocket/IXWebSocketVersion.h | 2 +- ws/ws_cobra_subscribe.cpp | 11 ++++++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 1798ec3e..7697dba1 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog All changes to this project will be documented in this file. +## [8.2.5] - 2020-03-13 + +(cobra client) ws cobra subscribe resubscribe at latest position after being disconnected + ## [8.2.4] - 2020-03-13 (cobra client) can subscribe with a position diff --git a/ixwebsocket/IXWebSocketVersion.h b/ixwebsocket/IXWebSocketVersion.h index c0390132..b50e9c51 100644 --- a/ixwebsocket/IXWebSocketVersion.h +++ b/ixwebsocket/IXWebSocketVersion.h @@ -6,4 +6,4 @@ #pragma once -#define IX_WEBSOCKET_VERSION "8.2.4" +#define IX_WEBSOCKET_VERSION "8.2.5" diff --git a/ws/ws_cobra_subscribe.cpp b/ws/ws_cobra_subscribe.cpp index 8e286a45..76ff95cc 100644 --- a/ws/ws_cobra_subscribe.cpp +++ b/ws/ws_cobra_subscribe.cpp @@ -68,8 +68,10 @@ namespace ix std::thread t(timer); + std::string subscriptionPosition(position); + conn.setEventCallback( - [&conn, &channel, &jsonWriter, &filter, &position, &msgCount, &msgPerSeconds, &quiet, &fluentd]( + [&conn, &channel, &jsonWriter, &filter, &subscriptionPosition, &msgCount, &msgPerSeconds, &quiet, &fluentd]( ix::CobraConnectionEventType eventType, const std::string& errMsg, const ix::WebSocketHttpHeaders& headers, @@ -87,10 +89,11 @@ namespace ix else if (eventType == ix::CobraConnection_EventType_Authenticated) { spdlog::info("Subscriber authenticated"); + spdlog::info("Subscribing to {} at position {}", channel, subscriptionPosition); conn.subscribe(channel, filter, - position, - [&jsonWriter, &quiet, &msgPerSeconds, &msgCount, &fluentd]( + subscriptionPosition, + [&jsonWriter, &quiet, &msgPerSeconds, &msgCount, &fluentd, &subscriptionPosition]( const Json::Value& msg, const std::string& position) { if (!quiet) { @@ -99,6 +102,8 @@ namespace ix msgPerSeconds++; msgCount++; + + subscriptionPosition = position; }); } else if (eventType == ix::CobraConnection_EventType_Subscribed)