Skip to content
oatpp client for consul
Branch: master
Clone or download
Latest commit 0d78a0d May 21, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
cmake update installation scripts Jan 28, 2019
src better API docs Mar 23, 2019
test updated to oatpp veraion 0.19.4 Apr 29, 2019
utility new module structure Jan 27, 2019
.gitignore new module structure Jan 27, 2019
CMakeLists.txt
LICENSE Initial commit Jun 30, 2018
README.md Update README.md May 21, 2019
azure-pipelines.yml Disable Azure-Pipelines MacOS builds as for oatpp/oatpp#66 Apr 30, 2019

README.md

oatpp-consul Build Status

oatpp-consul - extension for oatpp web framework.
It provides Consul integration for oatpp applications.

See more:

APIs

Example

For full example project see: oatpp-consul example

KV

#include "oatpp-consul/Client.hpp"

...
  
  /* request executor should be previously initialized */
  auto client = oatpp::consul::Client::createShared(requestExecutor);

  /* put value */
  client->kvPut("key1", "value1");
 
  /* get value */
  auto value = client->kvGet("key1");
  
  /* print value */
  OATPP_LOGD("consul", "value='%s'", value->c_str());
  
  /* get kv metadata */
  auto meta = client->kvGetMetadata("key1");
  
  /* decode and pring value from metadata */
  OATPP_LOGD("consul", "value='%s'", meta->getValueDecoded()->c_str());

...

Register Service

#include "oatpp-consul/Client.hpp"

...
  
  /* request executor should be previously initialized */
  auto client = oatpp::consul::Client::createShared(requestExecutor);
  
  /* get oatpp::consul::rest::Client */
  auto restClient = client->getRestClient();
  
  auto checkPayload = oatpp::consul::rest::AgentCheckRegisterPayload::createShared();
  checkPayload->id = "service_check_id";
  checkPayload->name = "service_check_name";
  checkPayload->notes = "Check on the MyService/Health endpoint";
  checkPayload->http = "http://localhost:8000/check/health";
  checkPayload->method = "GET";
  checkPayload->interval = "30s";
  checkPayload->timeout = "15s";
  
  auto payload = oatpp::consul::rest::AgentServiceRegisterPayload::createShared();
  payload->id = "service_id";
  payload->name = "service_name";
  payload->port = 8000;
  payload->check = checkPayload;
  
  /* make API call */
  auto response = restClient->agentServiceRegister(payload);
  
  OATPP_LOGD("consul", "response='%s'", response->readBodyToString()->c_str());
  
...
You can’t perform that action at this time.