Giter Site home page Giter Site logo

oatpp-consul's Introduction

oatpp-consul Build Status

oatpp client for consul

More about oatpp see https://oatpp.io/
More about consul API see https://www.consul.io/api/index.html

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());
  
...

oatpp-consul's People

Contributors

lganzzzo avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.