/* Test client for Zero MQ
Copyright (C) 2018-2024 Adam Leszczynski ([email protected])
This file is part of OpenLogReplicator.
OpenLogReplicator is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 3, or (at your option)
any later version.
OpenLogReplicator is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenLogReplicator; see the file LICENSE; If not see
. */
#include
#include "common/ClockHW.h"
#include "common/Ctx.h"
#include "common/OraProtoBuf.pb.h"
#include "common/types.h"
#include "common/exception/ConfigurationException.h"
#include "common/exception/DataException.h"
#include "common/exception/NetworkException.h"
#include "common/exception/RuntimeException.h"
#include "stream/StreamNetwork.h"
#ifdef LINK_LIBRARY_ZEROMQ
#include "stream/StreamZeroMQ.h"
#endif /* LINK_LIBRARY_ZEROMQ */
#define MAX_CLIENT_MESSAGE_SIZE (2*1024*1024*1024ul - 1)
void send(OpenLogReplicator::pb::RedoRequest& request, OpenLogReplicator::Stream* stream, OpenLogReplicator::Ctx* ctx __attribute__((unused))) {
std::string buffer;
bool ret = request.SerializeToString(&buffer);
if (!ret)
throw OpenLogReplicator::RuntimeException(0, "message serialization");
stream->sendMessage(buffer.c_str(), buffer.length());
}
uint64_t receive(OpenLogReplicator::pb::RedoResponse& response, OpenLogReplicator::Stream* stream, OpenLogReplicator::Ctx* ctx, uint8_t* buffer, bool decode) {
uint64_t length = stream->receiveMessage(buffer, MAX_CLIENT_MESSAGE_SIZE);
response.Clear();
if (decode && !response.ParseFromArray(buffer, length)) {
ctx->error(0, "response parse");
exit(0);
}
return length;
}
int main(int argc, char** argv) {
std::string olrLocales;
const char* olrLocalesStr = getenv("OLR_LOCALES");
if (olrLocalesStr != nullptr)
olrLocales = olrLocalesStr;
if (olrLocales == "MOCK")
OLR_LOCALES = OpenLogReplicator::Ctx::OLR_LOCALES_MOCK;
OpenLogReplicator::Ctx ctx;
const char* logTimezone = std::getenv("OLR_LOG_TIMEZONE");
if (logTimezone != nullptr)
if (!ctx.parseTimezone(logTimezone, ctx.logTimezone))
ctx.error(10070, "invalid environment variable OLR_LOG_TIMEZONE value: " + std::string(logTimezone));
ctx.welcome("OpenLogReplicator v." + std::to_string(OpenLogReplicator_VERSION_MAJOR) + "." +
std::to_string(OpenLogReplicator_VERSION_MINOR) + "." + std::to_string(OpenLogReplicator_VERSION_PATCH) +
" StreamClient (C) 2018-2024 by Adam Leszczynski ([email protected]), see LICENSE file for licensing information");
// Run arguments:
// 1. network|zeromq - type of communication protocol
// 2. uri - network: host:port, zeromq: tcp://host:port
// 3. database - database name
// 4. format - protobuf|json
// 5. The fifth parameter defines mode to start. If OpenLogReplicator is started for the first time, it would expect to define the position to start
// replication from. If it is running, it would expect the client to provide c:, - position of last confirmed message.
// Possible values are:
// now - start from NOW
// now - start from NOW but start parsing redo log from sequence
// scn: - start from given SCN
// scn:, - start from given SCN but start parsing redo log from sequence
// tm_rel: