content/references/java-chassis/en_US/transports/rest-over-vertx/index.html (460 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>REST over Vertx - 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 = "REST over Vertx";
var mkdocs_page_input_path = "transports/rest-over-vertx.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 class="current">
<li class="toctree-l1"><a class="reference internal" href="../rest-over-servlet/">REST over Servlet</a>
</li>
<li class="toctree-l1 current"><a class="reference internal current" href="./">REST over Vertx</a>
<ul class="current">
<li class="toctree-l2"><a class="reference internal" href="#configuration">Configuration</a>
<ul>
<li class="toctree-l3"><a class="reference internal" href="#supplementary-explanation">Supplementary Explanation</a>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#sample-code">Sample Code</a>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../highway-rpc/">Highway</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../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>
<li class="toctree-l1"><a class="reference internal" href="../../edge/open-service/">Intruductions</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../edge/by-servicecomb-sdk/">Using Edge Service</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../edge/nginx/">Using confd and Nginx as edge services</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../edge/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>Transports »</li>
<li>REST over Vertx</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="rest-over-vertx">REST over Vertx</h1>
<h2 id="configuration">Configuration</h2>
<p>The REST over Vertx communication channel runs in standalone mode, it can be started in the main function. In the main function, you need to initialize logs and load service configuration. The code is as follow:</p>
<pre><code class="language-java">import org.apache.servicecomb.foundation.common.utils.BeanUtils;
import org.apache.servicecomb.foundation.common.utils.Log4jUtils;
public class MainServer {
public static void main(String[] args) throws Exception {
Log4jUtils.init();// Log initialization
BeanUtils.init(); // Spring bean initialization
}
}
</code></pre>
<p>To use the REST over Vertx communication channel, add the following dependencies in the maven pom.xml file:</p>
<pre><code class="language-xml"><dependency>
<groupId>org.apache.servicecomb</groupId>
<artifactId>transport-rest-vertx</artifactId>
</dependency>
</code></pre>
<p>The REST over Vertx related configuration items in the microservice.yaml file are described as follows:</p>
<p>Table 1-1 Configuration items for REST over Vertx</p>
<table>
<thead>
<tr>
<th align="left">Configuration Item</th>
<th align="left">Default Value</th>
<th align="left">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">servicecomb.rest.address</td>
<td align="left"></td>
<td align="left">listening address, empty for not listen, just a rest client</td>
</tr>
<tr>
<td align="left">servicecomb.rest.server.connection-limit</td>
<td align="left">Integer.MAX_VALUE</td>
<td align="left">Max allowed client connections</td>
</tr>
<tr>
<td align="left">servicecomb.rest.server.thread-count</td>
<td align="left"><a href="../verticle-count/">verticle-count</a></td>
<td align="left">rest server verticle instance count(Deprecated)</td>
</tr>
<tr>
<td align="left">servicecomb.rest.server.verticle-count</td>
<td align="left"><a href="../verticle-count/">verticle-count</a></td>
<td align="left">rest server verticle instance count</td>
</tr>
<tr>
<td align="left">servicecomb.rest.server.connection.idleTimeoutInSeconds</td>
<td align="left">60</td>
<td align="left">Timeout for server's idle connection, The idle connections will be closed</td>
</tr>
<tr>
<td align="left">servicecomb.rest.server.compression</td>
<td align="left">false</td>
<td align="left">Wether the server support compression</td>
</tr>
<tr>
<td align="left">servicecomb.rest.server.maxInitialLineLength</td>
<td align="left">4096</td>
<td align="left">The max initial line length of the request the server can process, unit is Byte</td>
</tr>
<tr>
<td align="left">servicecomb.rest.server.maxHeaderSize</td>
<td align="left">32768</td>
<td align="left">The max header size of the request the server can process, unit is Byte</td>
</tr>
<tr>
<td align="left">servicecomb.rest.server.maxFormAttributeSize</td>
<td align="left">2048</td>
<td align="left">The max form attribute size of the request the server can process, unit is Byte</td>
</tr>
<tr>
<td align="left">servicecomb.rest.server.compressionLevel</td>
<td align="left">6</td>
<td align="left">The gzip/deflate compression level</td>
</tr>
<tr>
<td align="left">servicecomb.rest.server.maxChunkSize</td>
<td align="left">8192</td>
<td align="left">The max HTTP chunk size, unit is Byte</td>
</tr>
<tr>
<td align="left">servicecomb.rest.server.decoderInitialBufferSize</td>
<td align="left">128</td>
<td align="left">The max initial buffer size for HttpObjectDecoder, unit is Byte</td>
</tr>
<tr>
<td align="left">servicecomb.rest.server.http2ConnectionWindowSize</td>
<td align="left">-1</td>
<td align="left">HTTP/2 connection window size, unlimited</td>
</tr>
<tr>
<td align="left">servicecomb.rest.server.decompressionSupported</td>
<td align="left">false</td>
<td align="left">whether decompression is supported</td>
</tr>
<tr>
<td align="left">servicecomb.rest.client.thread-count</td>
<td align="left"><a href="../verticle-count/">verticle-count</a></td>
<td align="left">rest client verticle instance count(Deprecated)</td>
</tr>
<tr>
<td align="left">servicecomb.rest.client.verticle-count</td>
<td align="left"><a href="../verticle-count/">verticle-count</a></td>
<td align="left">rest client verticle instance count</td>
</tr>
<tr>
<td align="left">servicecomb.rest.client.connection.maxPoolSize</td>
<td align="left">5</td>
<td align="left">The maximum number of connections in each connection pool for an IP:port combination</td>
</tr>
<tr>
<td align="left">servicecomb.rest.client.connection.idleTimeoutInSeconds</td>
<td align="left">30</td>
<td align="left">Timeout for client's idle connection, The idle connections will be closed</td>
</tr>
<tr>
<td align="left">servicecomb.rest.client.connection.keepAlive</td>
<td align="left">true</td>
<td align="left">Whether to use long connections</td>
</tr>
<tr>
<td align="left">servicecomb.rest.client.connection.compression</td>
<td align="left">false</td>
<td align="left">Wether the client support compression</td>
</tr>
<tr>
<td align="left">servicecomb.rest.client.maxHeaderSize</td>
<td align="left">8192</td>
<td align="left">The max header size of the response the client can process, unit is Byte</td>
</tr>
</tbody>
</table>
<h3 id="supplementary-explanation">Supplementary Explanation</h3>
<ul>
<li>The connection amount under extreme condition
Assumption:</li>
<li>servicecomb.rest.client.thread-count = 8</li>
<li>servicecomb.rest.client.connection.maxPoolSize = 5</li>
<li>there are 10 instances of microservice A </li>
</ul>
<p>In terms of client side, under the extreme condition:
* for a client instance invoking microservice A, there are up to 400 connections.(<code>8 * 5 * 10 = 400</code>)
* if this client instance is also invoking another microservice B, and there are 10 instances of microservice B, then there are another 400 connections, and 800 connections in total.</p>
<p>In terms of server side, under the extreme condition:
* a client instance establishes up to 40 connections to a server instance.(<code>8 * 5 = 40</code>)
* <code>n</code> client instances establish up to <code>40 * n</code> connections to a server instance.</p>
<p>To improve performance, larger connection pools are needed. While the larger connection pools means the more connections. When the microservice instance scale reaches hundreds, some instances may handle tens of thousands of connections. Therefore, the developers need to make reasonable planning according to the actual condition.
The planning of HTTP1.1 may be relatively complex, and sometimes there is no proper solution, in which case the <a href="../http2/">http2</a> is recommended.</p>
<h2 id="sample-code">Sample Code</h2>
<p>An example of the configuration in the microservice.yaml file for REST over Vertx:</p>
<pre><code class="language-yaml">servicecomb:
rest:
address: 0.0.0.0:8080
thread-count: 1
references:
hello:
transport: rest
version-rule: 0.0.1
</code></pre>
</div>
</div><footer>
<div class="rst-footer-buttons" role="navigation" aria-label="Footer Navigation">
<a href="../rest-over-servlet/" class="btn btn-neutral float-left" title="REST over Servlet"><span class="icon icon-circle-arrow-left"></span> Previous</a>
<a href="../highway-rpc/" class="btn btn-neutral float-right" title="Highway">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="../rest-over-servlet/" style="color: #fcfcfc">« Previous</a></span>
<span><a href="../highway-rpc/" 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>