snake: stream sql mock + add republished channel option
This commit is contained in:
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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")
|
||||
{
|
||||
|
21
ixsnake/ixsnake/IXStreamSql.cpp
Normal file
21
ixsnake/ixsnake/IXStreamSql.cpp
Normal 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
|
24
ixsnake/ixsnake/IXStreamSql.h
Normal file
24
ixsnake/ixsnake/IXStreamSql.h
Normal 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:
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user