Giter Club home page Giter Club logo

apollo's Introduction

1.apollo c语言客户端

1.1 前置依赖

  • 依赖libcurl
  yum -y install libcurl libcurl-devel
  • 依赖json-c
  yum -y install json-c json-c-devel

源代码安装libcurl和json-c请参考其他教程。

1.2 编译

1.2.1 cygwin环境

window环境下使用cygwin编译,进入源代码根目录

  make -C ./cygwin all

安装到cygwin

  make -C ./cygwin install

其他指令

  • uninstall 卸载安装。
  • clean 清空源代码生成的库文件缓存。

1.2.2 linux环境

linux环境直接使用gcc,进入源代码根目录

  make all

安装到系统中

  make install

其他指令

  • uninstall 卸载安装。ls
  • clean 清空源代码生成的库文件缓存。

1.3调用

1.3.1不带缓存的Http接口从Apollo读取配置

引用头文件。

#include <apollo/apolloclient.h>

获取某个apollo上namespace对应的键值对

    apollo_env apolloEnv={
        meta:"192.168.1.65:16001",
        appId:"ms-apigateway",
        clusterName:"default",
        namespaceName:"application.yml"
    };
    Properties properties;
    getNoCacheProperty(apolloEnv,&properties);

其中Properties封装了返回键值对信息。

typedef struct {
    size_t len; /**键值对个数**/
    String* keys; /**键数组**/
    String* values; /**值数组**/
} Properties;

注意一下几点:

  1. property类型配置,返回多个对应键值对结果。
  2. json和yaml类型配置返回唯一键值对,keys 固定为content。

1.3.2应用感知配置更新

应用注册后,当配置中心发生变化后自动推送更新到回调函数。

    apollo_env apolloEnv={
        meta:"192.168.1.65:16001",
        appId:"ms-apigateway",
        clusterName:"default",
        namespaceName:NULL
    };
   notification notifications={
        namespaceName:"application.yml",
        notificationId:-1
    };
   //参数3表示异步线程是否继续运行,可定义指针 int* 当该值为0时,long pooling将停止。
   submitNotificationsAsync(apolloEnv,notifications,1,updateConfig);

定义回调函数updateConfig

/**
  old表示此次更新旧配置,new表示新配置。
  第一次回调old是NULL。
**/
void updateConfig(Properties* old,Properties* new){
    //对应的处理逻辑
}

apollo's People

Contributors

gvtcy avatar lzeqian 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.