Closed joconnor-openet closed 5 years ago
/*
* g++ -std=c++11 -o ppconsul-meta-bug ppconsul-meta-bug.cc -I/path/to/ppconsul/include/ -I/usr/local64/boost/boost_1_55_0/include -L/path/to/ppconsul/lib -lppconsul
*/
#include <ppconsul/consul.h>
#include <ppconsul/catalog.h>
#include <chrono>
using namespace ppconsul;
using namespace std;
int main(int argc, char *argv[]) {
try {
Consul consul("http://127.0.0.1:8500");
catalog::Catalog catalog(consul);
uint64_t index = 0;
auto response = catalog.service(withHeaders, "name1", catalog::kw::block_for = {std::chrono::seconds(10), index});
index = response.headers().index();
std::cout << "index=" << index << std::endl;
std::for_each(response.data().begin(), response.data().end(), [](catalog::NodeService& nodeService){
ServiceInfo& serviceInfo = nodeService.second;
std::cout << "Address: " << serviceInfo.address << std::endl;
std::cout << "ID: " << serviceInfo.id << std::endl;
std::cout << "Name: " << serviceInfo.name << std::endl;
std::cout << "Port: " << serviceInfo.port << std::endl;
std::cout << "Tags: " << std::endl;
for (const auto& tag: serviceInfo.tags) {
std::cout << "\t" << tag << std::endl;
}
std::cout << "Metadata: " << std::endl;
for (const auto& meta: serviceInfo.meta) {
std::cout << "\t" << meta.first << "=>" << meta.second << std::endl;
}
});
} catch(std::exception& e) {
std::cout << e.what() << std::endl;
}
}
Proposed fix, works when testing locally:
diff --git a/src/catalog.cpp b/src/catalog.cpp
index 5d38e601..cbd03404 100644
--- a/src/catalog.cpp
+++ b/src/catalog.cpp
@@ -20,6 +20,7 @@ namespace json11 {
load(src, dst.second.address, "ServiceAddress");
load(src, dst.second.port, "ServicePort");
load(src, dst.second.tags, "ServiceTags");
+ load(src, dst.second.meta, "ServiceMeta");
}
void load(const json11::Json& src, ppconsul::catalog::NodeServices& dst)
Should be fixed now
Followon from https://github.com/oliora/ppconsul/issues/29 Version: git revision 6a1a8aa5 on Centos 7.7.1908
When discovering service info, the "ServiceInfo.meta" map is not populated.
Steps to reproduce:
Expected results:
Actual results: