snake: stream sql mock + add republished channel option

This commit is contained in:
Benjamin Sergeant
2020-07-10 15:06:55 -07:00
parent c98959b895
commit 26a1e63626
11 changed files with 102 additions and 4 deletions

View File

@ -7,12 +7,14 @@ set (IXSNAKE_SOURCES
ixsnake/IXSnakeServer.cpp
ixsnake/IXSnakeProtocol.cpp
ixsnake/IXAppConfig.cpp
ixsnake/IXStreamSql.cpp
)
set (IXSNAKE_HEADERS
ixsnake/IXSnakeServer.h
ixsnake/IXSnakeProtocol.h
ixsnake/IXAppConfig.h
ixsnake/IXStreamSql.h
)
add_library(ixsnake STATIC

View File

@ -33,6 +33,9 @@ namespace snake
// Misc
bool verbose;
bool disablePong;
// If non empty, every published message gets republished to a given channel
std::string republishChannel;
};
bool isAppKeyValid(const AppConfig& appConfig, std::string appkey);

View File

@ -30,6 +30,7 @@ namespace snake
{
return _appkey;
}
void setAppkey(const std::string& appkey)
{
_appkey = appkey;
@ -39,6 +40,7 @@ namespace snake
{
return _role;
}
void setRole(const std::string& role)
{
_role = role;

View File

@ -91,6 +91,7 @@ namespace snake
void handlePublish(std::shared_ptr<SnakeConnectionState> state,
std::shared_ptr<ix::WebSocket> ws,
const AppConfig& appConfig,
const nlohmann::json& pdu)
{
std::vector<std::string> channels;
@ -115,6 +116,12 @@ namespace snake
return;
}
// add an extra channel if the config has one specified
if (!appConfig.republishChannel.empty())
{
channels.push_back(appConfig.republishChannel);
}
for (auto&& channel : channels)
{
std::stringstream ss;
@ -279,7 +286,7 @@ namespace snake
}
else if (action == "rtm/publish")
{
handlePublish(state, ws, pdu);
handlePublish(state, ws, appConfig, pdu);
}
else if (action == "rtm/subscribe")
{

View File

@ -0,0 +1,21 @@
/*
* IXStreamSql.cpp
* Author: Benjamin Sergeant
* Copyright (c) 2020 Machine Zone, Inc. All rights reserved.
*/
#include "IXStreamSql.h"
namespace snake
{
StreamSql::StreamSql(const std::string& sqlFilter)
{
;
}
bool StreamSql::match(const nlohmann::json& pdu)
{
return true;
}
} // namespace snake

View File

@ -0,0 +1,24 @@
/*
* IXStreamSql.h
* Author: Benjamin Sergeant
* Copyright (c) 2020 Machine Zone, Inc. All rights reserved.
*/
#pragma once
#include <string>
#include "nlohmann/json.hpp"
namespace snake
{
class StreamSql
{
public:
StreamSql(const std::string& sqlFilter);
~StreamSql() = default;
bool match(const nlohmann::json& pdu);
private:
};
}