content/references/java-chassis/en_US/edge/nginx/index.html (392 lines of code) (raw):
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="shortcut icon" href="../../img/favicon.ico" />
<title>Using confd and Nginx as edge services - ServiceComb Java Chassis Developers Guide</title>
<link rel="stylesheet" href="../../css/theme.css" />
<link rel="stylesheet" href="../../css/theme_extra.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/github.min.css" />
<script>
// Current page data
var mkdocs_page_name = "Using confd and Nginx as edge services";
var mkdocs_page_input_path = "edge/nginx.md";
var mkdocs_page_url = null;
</script>
<script src="../../js/jquery-3.6.0.min.js" defer></script>
<!--[if lt IE 9]>
<script src="../../js/html5shiv.min.js"></script>
<![endif]-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
<div class="wy-side-scroll">
<div class="wy-side-nav-search">
<a href="../.." class="icon icon-home"> ServiceComb Java Chassis Developers Guide
</a><div role="search">
<form id ="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" title="Type search term here" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../..">Introduction</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Getting Started</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../start/terminology/">Glossary</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../start/architecture/">Architecture</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../start/development-environment/">Development environment</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../start/first-sample/">Develop the first microservice</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Development Service Provider</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../build-provider/definition/service-definition/">Service definition</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../build-provider/define-contract/">Service contract definition</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../build-provider/code-first/">Implicit API definition</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../build-provider/swagger-annotation/">Use Swagger annotations</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../build-provider/springmvc/">Develop with SpringMVC</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../build-provider/jaxrs/">Develop with JAX-RS</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../build-provider/transparent-rpc/">Develop with Transparent RPC</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../build-provider/interface-constraints/">Interface definition and data type</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../build-provider/listen-address-and-publish-address/">Service listening address and publishing address</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../build-provider/thread-pool/">Thread pool</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="#">Service Configuration</a>
<ul>
<li class="toctree-l2"><a class="reference internal" href="../../build-provider/configuration/ratelimite-strategy/">Rate Limiting Policy</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../build-provider/configuration/downgrade-strategy/">Fallback Policy</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../build-provider/configuration/parameter-validator/">Parameter Validator</a>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../build-provider/bootup/">Boot-up Process</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../build-provider/access-log-configuration/">Access Log Configuration</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Writing Service Consumer</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../build-consumer/common-configuration/">Consumer common configuration</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../build-consumer/using-resttemplate/">Using Rest Template</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../build-consumer/using-AsyncRestTemplate/">Using AsyncRestTemplate</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../build-consumer/develop-consumer-using-rpc/">Using with RPC</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../build-consumer/with-contract/">Contract</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="#">Invoke control</a>
<ul>
<li class="toctree-l2"><a class="reference internal" href="../../build-consumer/circuit-breaker/">Circuit Breaker</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../build-consumer/flow-control/">Flow Control</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../build-consumer/fault-injection/">Fault Injection</a>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../build-consumer/3rd-party-service-invoke/">Invoke 3rd-party REST services</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Transports</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../transports/rest-over-servlet/">REST over Servlet</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../transports/rest-over-vertx/">REST over Vertx</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../transports/highway-rpc/">Highway</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../transports/http2/">HTTP2</a>
</li>
</ul>
<p class="caption"><span class="caption-text">General Development</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/visit-sc/">Access Service Center</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/metrics/">Metrics</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/microservice-invocation-chain/">Microservice invocation chain</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/customized-tracing/">Customized-Tracing</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/local-develop-test/">Local development and testing</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/http-filter/">Http Filter</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/file-upload/">File Uploading</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/file-download/">File Downloading</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/reactive/">Reactive Programing</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/dnsconfig/">DNS Custom Configuration</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/dai-li-she-zhi/">Proxy Settings</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/report-framework-version/">Report framework version</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/cross-app-invocation/">Cross-application invocation</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/secret-field/">Customized serialization and deserialization</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/context/">Using Context to pass control messages</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/produceprocess/">Return value serialization extension</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/CORS/">CORS mechanism</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/AlarmEvent/">Get fuse and instance isolation alarm event information</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/shutdown/">Shutdown gracefully</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/error-handling/">Handling exceptions</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/multienvironment/">Multi-environment isolation between microservice instances</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/thread-model/">Thread Model</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Configuration</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../config/general-config/">General config</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../config/inject-config/">Configuration injection</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Service Capability Open</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../open-service/">Intruductions</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../by-servicecomb-sdk/">Using Edge Service</a>
</li>
<li class="toctree-l1 current"><a class="reference internal current" href="./">Using confd and Nginx as edge services</a>
<ul class="current">
<li class="toctree-l2"><a class="reference internal" href="#concept-description">Concept Description</a>
<ul>
<li class="toctree-l3"><a class="reference internal" href="#confd">confd</a>
</li>
<li class="toctree-l3"><a class="reference internal" href="#nginx">Nginx</a>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#scene-description">Scene Description</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#docking-service-center">Docking Service Center</a>
<ul>
<li class="toctree-l3"><a class="reference internal" href="#method-one-http-call">Method one: http call</a>
<ul>
<li class="toctree-l4"><a class="reference internal" href="#note-in-actual-development-please-visit-the-actual-service-center-access-address-and-replace-the-variable-of-in-the-above-url-with-a-specific-value-the-data-returned-by-http-is-in-json-format">Note: In actual development, please visit the actual service-center access address, and replace the variable of {} in the above url with a specific value. The data returned by http is in json format.</a>
</li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#method-2-use-servicecomb-open-source-code-interface">Method 2: Use servicecomb open source code interface</a>
</li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../zuul/">Use zuul as edge services</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Service Packing and Running</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../packaging/standalone/">Standalone mode</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../packaging/web-container/">WEB container mode</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Micro Service Security</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../security/tls/">Using TLS</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../security/rsa/">Using RSA certification</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Using java chassis in Spring Boot</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../using-java-chassis-in-spring-boot/using-java-chassis-in-spring-boot/">Intruductions</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../using-java-chassis-in-spring-boot/components-for-spring-boot/">spring boot starter for java-chassis</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../using-java-chassis-in-spring-boot/java-application/">JAVA application development</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../using-java-chassis-in-spring-boot/web-application/">Web development method development</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../using-java-chassis-in-spring-boot/diff-between-java-web/">The difference between JAVA application method and Web development method</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../using-java-chassis-in-spring-boot/diff-spring-mvc/">The difference in Spring MVC mode</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Handlers reference</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../references-handlers/intruduction/">Intruductions</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../references-handlers/loadbalance/">Load Balancing</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../references-handlers/publickey/">Public key authentication</a>
</li>
</ul>
<p class="caption"><span class="caption-text">FAQ</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../question-and-answer/question_answer/">Q & A</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../question-and-answer/faq/">FAQ</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../question-and-answer/interface-compatibility/">Micro Service Interface Compatibility FAQ</a>
</li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="Mobile navigation menu">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../..">ServiceComb Java Chassis Developers Guide</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content"><div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../.." class="icon icon-home" alt="Docs"></a> »</li>
<li>Service Capability Open »</li>
<li>Using confd and Nginx as edge services</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div class="section" itemprop="articleBody">
<h1 id="using-confd-and-nginx-for-edge-services">Using confd and Nginx for edge services</h1>
<h2 id="concept-description">Concept Description</h2>
<h3 id="confd"><strong>confd</strong></h3>
<p>Confd is a lightweight configuration management tool, source code: [https://github.com/kelseyhightower/confd] (https://github.com/kelseyhightower/confd), which stores configuration information in etcd, Consul, dynamodb, redis, and zookeeper. Confd periodically pulls the latest configuration from these storage nodes, then reloads the service and completes the configuration file update.</p>
<h3 id="nginx"><strong>Nginx</strong></h3>
<p>Nginx (engine x) is a high-performance HTTP and reverse proxy server with load balancing capabilities. For details, please refer to [http://www.nginx.cn/doc/] (http://www.nginx.cn/doc/). The services introduced in this section mainly use the Nginx http proxy function.</p>
<h2 id="scene-description">Scene Description</h2>
<p>The technology introduced in this section is to use nginx+confd as the edge service. At the same time, you can dock the service center in the Java Chassis microservices framework, and pull the service information from the service center to dynamically update the nginx configuration through confd.</p>
<p>The implementation steps of using nginx+confd dynamic reverse proxy can be found in the article [http://www.cnblogs.com/Anker/p/6112022.html] (http://www.cnblogs.com/Anker/p/6112022. Html), this section mainly introduces how confd docks the service center of the Java Chassis framework.</p>
<h2 id="docking-service-center">Docking Service Center</h2>
<p>The core of the technology introduced in this section is how to make confd get the service information of the service center. The service center opens the following interfaces for external calls:</p>
<h3 id="method-one-http-call"><strong>Method one: http call </strong></h3>
<p>The service provider open http interface needs to add the tenant header information: "X-Tenant-Name:tenantName", and the tenameName is the tenant name. The default is default, for example, "X-Tenant-Name: default".</p>
<ul>
<li>Check the health status of the service center</li>
</ul>
<p><code>GET 127.0.0.1:30100/health</code></p>
<ul>
<li>Get all micro service information</li>
</ul>
<p><code>GET 127.0.0.1:30100/registry/v3/microservices</code></p>
<ul>
<li>Get the microservice information of the specified id</li>
</ul>
<blockquote>
<ol>
<li>First get the serviceId based on the microservice information</li>
</ol>
<p><code>GET 127.0.0.1:30100/registry/v3/existence?type=microservice&appId={appId}&serviceName={serviceName}&version={version}</code></p>
<ol>
<li>
<ol>
<li>Obtain the microservice complete information according to the serviceId returned by the above interface.</li>
</ol>
</li>
</ol>
<p>GET 127.0.0.1:30100/registry/v3/microservices/{serviceId}</p>
</blockquote>
<ul>
<li>Get all instance information for the specified microservice</li>
</ul>
<p>```
GET 127.0.0.1:30100/registry/v3/microservices/{serviceId}/instances</p>
<p>Need to add in the header: "X-ConsumerId: {serviceId}".
```</p>
<ul>
<li>Find micro service instance information</li>
</ul>
<p>```
GET 127.0.0.1:30100/registry/v3/instances?appId={appId}&serviceName={serviceName}&version={version}</p>
<p>Need to add in the header: "X-ConsumerId: {serviceId}".
```</p>
<h4 id="note-in-actual-development-please-visit-the-actual-service-center-access-address-and-replace-the-variable-of-in-the-above-url-with-a-specific-value-the-data-returned-by-http-is-in-json-format">Note: In actual development, please visit the actual service-center access address, and replace the variable of {} in the above url with a specific value. The data returned by http is in json format.</h4>
<h3 id="method-2-use-servicecomb-open-source-code-interface"><strong>Method 2: Use servicecomb open source code interface</strong></h3>
<p>In the development of microservices applications, you only need to call the interface provided in the tool class RegistryUtil.java in the servicecomb framework code to get the information of the service center. The interface description is as follows:</p>
<ul>
<li>Get all micro service information</li>
</ul>
<p><code>java
List<Microservice> getAllMicroservices();</code></p>
<ul>
<li>Get the microservice unique identifier</li>
</ul>
<p><code>java
String getMicroserviceId(String appId, String microserviceName, String versionRule);</code></p>
<ul>
<li>Query microservice static information based on microservice unique identifier</li>
</ul>
<p><code>java
Microservice getMicroservice(String microserviceId);</code></p>
<ul>
<li>Query all micro service instance information based on multiple microservice unique identifiers</li>
</ul>
<p><code>java
List<MicroserviceInstance> getMicroserviceInstance(String consumerId, String providerId);</code></p>
<ul>
<li>Query instance endpoints information by app+interface+version</li>
</ul>
<p><code>java
List<MicroserviceInstance> findServiceInstance(String consumerId, String appId, String serviceName, String versionRule);</code></p>
<p>Through the above http interface, information about the microservices of the service center and its instances can be obtained, thereby dynamically updating the nginx configuration through confd.</p>
</div>
</div><footer>
<div class="rst-footer-buttons" role="navigation" aria-label="Footer Navigation">
<a href="../by-servicecomb-sdk/" class="btn btn-neutral float-left" title="Using Edge Service"><span class="icon icon-circle-arrow-left"></span> Previous</a>
<a href="../zuul/" class="btn btn-neutral float-right" title="Use zuul as edge services">Next <span class="icon icon-circle-arrow-right"></span></a>
</div>
<hr/>
<div role="contentinfo">
<!-- Copyright etc -->
</div>
Built with <a href="https://www.mkdocs.org/">MkDocs</a> using a <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<div class="rst-versions" role="note" aria-label="Versions">
<span class="rst-current-version" data-toggle="rst-current-version">
<span><a href="../by-servicecomb-sdk/" style="color: #fcfcfc">« Previous</a></span>
<span><a href="../zuul/" style="color: #fcfcfc">Next »</a></span>
</span>
</div>
<script>var base_url = '../..';</script>
<script src="../../js/theme_extra.js" defer></script>
<script src="../../js/theme.js" defer></script>
<script src="../../search/main.js" defer></script>
<script defer>
window.onload = function () {
SphinxRtdTheme.Navigation.enable(true);
};
</script>
</body>
</html>