blob: e6a7a0f125eadccdd32f8700cae09c5c55bbbe11 [file] [log] [blame]
<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="prev" href="../file-download/">
<link rel="next" href="../dnsconfig/">
<link rel="icon" href="../../assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.6.0, mkdocs-material-9.5.19">
<title>Reactive Programing - ServiceComb Java Chassis Developers Guide</title>
<link rel="stylesheet" href="../../assets/stylesheets/main.66ac8b77.min.css">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
<style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
<script>__md_scope=new URL("../..",location),__md_hash=e=>[...e].reduce((e,_)=>(e<<5)-e+_.charCodeAt(0),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
</head>
<body dir="ltr">
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
<label class="md-overlay" for="__drawer"></label>
<div data-md-component="skip">
<a href="#simple-synchronization-mode-producer" class="md-skip">
Skip to content
</a>
</div>
<div data-md-component="announce">
</div>
<header class="md-header md-header--shadow" data-md-component="header">
<nav class="md-header__inner md-grid" aria-label="Header">
<a href="../.." title="ServiceComb Java Chassis Developers Guide" class="md-header__button md-logo" aria-label="ServiceComb Java Chassis Developers Guide" data-md-component="logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54Z"/></svg>
</a>
<label class="md-header__button md-icon" for="__drawer">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2Z"/></svg>
</label>
<div class="md-header__title" data-md-component="header-title">
<div class="md-header__ellipsis">
<div class="md-header__topic">
<span class="md-ellipsis">
ServiceComb Java Chassis Developers Guide
</span>
</div>
<div class="md-header__topic" data-md-component="header-topic">
<span class="md-ellipsis">
Reactive Programing
</span>
</div>
</div>
</div>
<script>var media,input,key,value,palette=__md_get("__palette");if(palette&&palette.color){"(prefers-color-scheme)"===palette.color.media&&(media=matchMedia("(prefers-color-scheme: light)"),input=document.querySelector(media.matches?"[data-md-color-media='(prefers-color-scheme: light)']":"[data-md-color-media='(prefers-color-scheme: dark)']"),palette.color.media=input.getAttribute("data-md-color-media"),palette.color.scheme=input.getAttribute("data-md-color-scheme"),palette.color.primary=input.getAttribute("data-md-color-primary"),palette.color.accent=input.getAttribute("data-md-color-accent"));for([key,value]of Object.entries(palette.color))document.body.setAttribute("data-md-color-"+key,value)}</script>
<label class="md-header__button md-icon" for="__search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
</label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
<form class="md-search__form" name="search">
<input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
<label class="md-search__icon md-icon" for="__search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
</label>
<nav class="md-search__options" aria-label="Search">
<button type="reset" class="md-search__icon md-icon" title="Clear" aria-label="Clear" tabindex="-1">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41Z"/></svg>
</button>
</nav>
</form>
<div class="md-search__output">
<div class="md-search__scrollwrap" data-md-scrollfix>
<div class="md-search-result" data-md-component="search-result">
<div class="md-search-result__meta">
Initializing search
</div>
<ol class="md-search-result__list" role="presentation"></ol>
</div>
</div>
</div>
</div>
</div>
</nav>
</header>
<div class="md-container" data-md-component="container">
<main class="md-main" data-md-component="main">
<div class="md-main__inner md-grid">
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
<label class="md-nav__title" for="__drawer">
<a href="../.." title="ServiceComb Java Chassis Developers Guide" class="md-nav__button md-logo" aria-label="ServiceComb Java Chassis Developers Guide" data-md-component="logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54Z"/></svg>
</a>
ServiceComb Java Chassis Developers Guide
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../.." class="md-nav__link">
<span class="md-ellipsis">
Introduction
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_2" >
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
<span class="md-ellipsis">
Getting Started
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_2_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_2">
<span class="md-nav__icon md-icon"></span>
Getting Started
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../start/terminology/" class="md-nav__link">
<span class="md-ellipsis">
Glossary
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../start/architecture/" class="md-nav__link">
<span class="md-ellipsis">
Architecture
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../start/development-environment/" class="md-nav__link">
<span class="md-ellipsis">
Development environment
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../start/first-sample/" class="md-nav__link">
<span class="md-ellipsis">
Develop the first microservice
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3" >
<label class="md-nav__link" for="__nav_3" id="__nav_3_label" tabindex="0">
<span class="md-ellipsis">
Development Service Provider
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_3_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_3">
<span class="md-nav__icon md-icon"></span>
Development Service Provider
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../build-provider/definition/service-definition/" class="md-nav__link">
<span class="md-ellipsis">
Service definition
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../build-provider/define-contract/" class="md-nav__link">
<span class="md-ellipsis">
Service contract definition
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../build-provider/code-first/" class="md-nav__link">
<span class="md-ellipsis">
Implicit API definition
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../build-provider/swagger-annotation/" class="md-nav__link">
<span class="md-ellipsis">
Use Swagger annotations
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../build-provider/springmvc/" class="md-nav__link">
<span class="md-ellipsis">
Develop with SpringMVC
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../build-provider/jaxrs/" class="md-nav__link">
<span class="md-ellipsis">
Develop with JAX-RS
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../build-provider/transparent-rpc/" class="md-nav__link">
<span class="md-ellipsis">
Develop with Transparent RPC
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../build-provider/interface-constraints/" class="md-nav__link">
<span class="md-ellipsis">
Interface definition and data type
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../build-provider/listen-address-and-publish-address/" class="md-nav__link">
<span class="md-ellipsis">
Service listening address and publishing address
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../build-provider/thread-pool/" class="md-nav__link">
<span class="md-ellipsis">
Thread pool
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3_11" >
<label class="md-nav__link" for="__nav_3_11" id="__nav_3_11_label" tabindex="0">
<span class="md-ellipsis">
Service Configuration
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_3_11_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_3_11">
<span class="md-nav__icon md-icon"></span>
Service Configuration
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../build-provider/configuration/ratelimite-strategy/" class="md-nav__link">
<span class="md-ellipsis">
Rate Limiting Policy
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../build-provider/configuration/parameter-validator/" class="md-nav__link">
<span class="md-ellipsis">
Parameter Validator
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../../build-provider/bootup/" class="md-nav__link">
<span class="md-ellipsis">
Boot-up Process
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../build-provider/access-log-configuration/" class="md-nav__link">
<span class="md-ellipsis">
Access Log Configuration
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_4" >
<label class="md-nav__link" for="__nav_4" id="__nav_4_label" tabindex="0">
<span class="md-ellipsis">
Writing Service Consumer
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_4_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_4">
<span class="md-nav__icon md-icon"></span>
Writing Service Consumer
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../build-consumer/common-configuration/" class="md-nav__link">
<span class="md-ellipsis">
Consumer common configuration
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../build-consumer/using-resttemplate/" class="md-nav__link">
<span class="md-ellipsis">
Using Rest Template
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../build-consumer/using-AsyncRestTemplate/" class="md-nav__link">
<span class="md-ellipsis">
Using AsyncRestTemplate
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../build-consumer/develop-consumer-using-rpc/" class="md-nav__link">
<span class="md-ellipsis">
Using with RPC
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../build-consumer/with-contract/" class="md-nav__link">
<span class="md-ellipsis">
Contract
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_4_6" >
<label class="md-nav__link" for="__nav_4_6" id="__nav_4_6_label" tabindex="0">
<span class="md-ellipsis">
Invoke control
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_4_6_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_4_6">
<span class="md-nav__icon md-icon"></span>
Invoke control
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../build-consumer/flow-control/" class="md-nav__link">
<span class="md-ellipsis">
Flow Control
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../build-consumer/fault-injection/" class="md-nav__link">
<span class="md-ellipsis">
Fault Injection
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../../build-consumer/3rd-party-service-invoke/" class="md-nav__link">
<span class="md-ellipsis">
Invoke 3rd-party REST services
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5" >
<label class="md-nav__link" for="__nav_5" id="__nav_5_label" tabindex="0">
<span class="md-ellipsis">
Transports
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_5_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_5">
<span class="md-nav__icon md-icon"></span>
Transports
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../transports/rest-over-servlet/" class="md-nav__link">
<span class="md-ellipsis">
REST over Servlet
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../transports/rest-over-vertx/" class="md-nav__link">
<span class="md-ellipsis">
REST over Vertx
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../transports/highway-rpc/" class="md-nav__link">
<span class="md-ellipsis">
Highway
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../transports/http2/" class="md-nav__link">
<span class="md-ellipsis">
HTTP2
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--active md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_6" checked>
<label class="md-nav__link" for="__nav_6" id="__nav_6_label" tabindex="0">
<span class="md-ellipsis">
General Development
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_6_label" aria-expanded="true">
<label class="md-nav__title" for="__nav_6">
<span class="md-nav__icon md-icon"></span>
General Development
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../visit-sc/" class="md-nav__link">
<span class="md-ellipsis">
Access Service Center
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../metrics/" class="md-nav__link">
<span class="md-ellipsis">
Metrics
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../microservice-invocation-chain/" class="md-nav__link">
<span class="md-ellipsis">
Microservice invocation chain
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../customized-tracing/" class="md-nav__link">
<span class="md-ellipsis">
Customized-Tracing
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../local-develop-test/" class="md-nav__link">
<span class="md-ellipsis">
Local development and testing
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../http-filter/" class="md-nav__link">
<span class="md-ellipsis">
Http Filter
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../file-upload/" class="md-nav__link">
<span class="md-ellipsis">
File Uploading
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../file-download/" class="md-nav__link">
<span class="md-ellipsis">
File Downloading
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--active">
<input class="md-nav__toggle md-toggle" type="checkbox" id="__toc">
<label class="md-nav__link md-nav__link--active" for="__toc">
<span class="md-ellipsis">
Reactive Programing
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<a href="./" class="md-nav__link md-nav__link--active">
<span class="md-ellipsis">
Reactive Programing
</span>
</a>
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#simple-synchronization-mode-producer" class="md-nav__link">
<span class="md-ellipsis">
Simple Synchronization Mode Producer:
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#nested-synchronous-call" class="md-nav__link">
<span class="md-ellipsis">
Nested synchronous call:
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#error-optimization-for-nested-synchronous-calls" class="md-nav__link">
<span class="md-ellipsis">
"Error" optimization for nested synchronous calls:
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#pure-reactive-mechanism" class="md-nav__link">
<span class="md-ellipsis">
Pure Reactive Mechanism
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#hybrid-reactive-mechanism" class="md-nav__link">
<span class="md-ellipsis">
Hybrid Reactive Mechanism
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#some-notes-about-reactive" class="md-nav__link">
<span class="md-ellipsis">
Some notes about reactive:
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../dnsconfig/" class="md-nav__link">
<span class="md-ellipsis">
DNS Custom Configuration
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../dai-li-she-zhi/" class="md-nav__link">
<span class="md-ellipsis">
Proxy Settings
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../report-framework-version/" class="md-nav__link">
<span class="md-ellipsis">
Report framework version
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../cross-app-invocation/" class="md-nav__link">
<span class="md-ellipsis">
Cross-application invocation
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../secret-field/" class="md-nav__link">
<span class="md-ellipsis">
Customized serialization and deserialization
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../context/" class="md-nav__link">
<span class="md-ellipsis">
Using Context to pass control messages
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../produceprocess/" class="md-nav__link">
<span class="md-ellipsis">
Return value serialization extension
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../CORS/" class="md-nav__link">
<span class="md-ellipsis">
CORS mechanism
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../AlarmEvent/" class="md-nav__link">
<span class="md-ellipsis">
Get fuse and instance isolation alarm event information
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../shutdown/" class="md-nav__link">
<span class="md-ellipsis">
Shutdown gracefully
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../error-handling/" class="md-nav__link">
<span class="md-ellipsis">
Handling exceptions
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../multienvironment/" class="md-nav__link">
<span class="md-ellipsis">
Multi-environment isolation between microservice instances
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../thread-model/" class="md-nav__link">
<span class="md-ellipsis">
Thread Model
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_7" >
<label class="md-nav__link" for="__nav_7" id="__nav_7_label" tabindex="0">
<span class="md-ellipsis">
Configuration
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_7_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_7">
<span class="md-nav__icon md-icon"></span>
Configuration
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../config/general-config/" class="md-nav__link">
<span class="md-ellipsis">
General config
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../config/inject-config/" class="md-nav__link">
<span class="md-ellipsis">
Configuration injection
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_8" >
<label class="md-nav__link" for="__nav_8" id="__nav_8_label" tabindex="0">
<span class="md-ellipsis">
Service Capability Open
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_8_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_8">
<span class="md-nav__icon md-icon"></span>
Service Capability Open
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../edge/open-service/" class="md-nav__link">
<span class="md-ellipsis">
Intruductions
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../edge/by-servicecomb-sdk/" class="md-nav__link">
<span class="md-ellipsis">
Using Edge Service
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../edge/nginx/" class="md-nav__link">
<span class="md-ellipsis">
Using confd and Nginx as edge services
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../edge/zuul/" class="md-nav__link">
<span class="md-ellipsis">
Use zuul as edge services
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_9" >
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
<span class="md-ellipsis">
Service Packing and Running
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_9_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_9">
<span class="md-nav__icon md-icon"></span>
Service Packing and Running
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../packaging/standalone/" class="md-nav__link">
<span class="md-ellipsis">
Standalone mode
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../packaging/web-container/" class="md-nav__link">
<span class="md-ellipsis">
WEB container mode
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_10" >
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
<span class="md-ellipsis">
Micro Service Security
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_10_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_10">
<span class="md-nav__icon md-icon"></span>
Micro Service Security
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../security/tls/" class="md-nav__link">
<span class="md-ellipsis">
Using TLS
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../security/rsa/" class="md-nav__link">
<span class="md-ellipsis">
Using RSA certification
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_11" >
<label class="md-nav__link" for="__nav_11" id="__nav_11_label" tabindex="0">
<span class="md-ellipsis">
Using java chassis in Spring Boot
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_11_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_11">
<span class="md-nav__icon md-icon"></span>
Using java chassis in Spring Boot
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../using-java-chassis-in-spring-boot/using-java-chassis-in-spring-boot/" class="md-nav__link">
<span class="md-ellipsis">
Intruductions
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../using-java-chassis-in-spring-boot/components-for-spring-boot/" class="md-nav__link">
<span class="md-ellipsis">
spring boot starter for java-chassis
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../using-java-chassis-in-spring-boot/java-application/" class="md-nav__link">
<span class="md-ellipsis">
JAVA application development
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../using-java-chassis-in-spring-boot/web-application/" class="md-nav__link">
<span class="md-ellipsis">
Web development method development
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../using-java-chassis-in-spring-boot/diff-between-java-web/" class="md-nav__link">
<span class="md-ellipsis">
The difference between JAVA application method and Web development method
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../using-java-chassis-in-spring-boot/diff-spring-mvc/" class="md-nav__link">
<span class="md-ellipsis">
The difference in Spring MVC mode
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_12" >
<label class="md-nav__link" for="__nav_12" id="__nav_12_label" tabindex="0">
<span class="md-ellipsis">
Handlers reference
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_12_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_12">
<span class="md-nav__icon md-icon"></span>
Handlers reference
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../references-handlers/intruduction/" class="md-nav__link">
<span class="md-ellipsis">
Intruductions
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../references-handlers/loadbalance/" class="md-nav__link">
<span class="md-ellipsis">
Load Balancing
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../references-handlers/publickey/" class="md-nav__link">
<span class="md-ellipsis">
Public key authentication
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_13" >
<label class="md-nav__link" for="__nav_13" id="__nav_13_label" tabindex="0">
<span class="md-ellipsis">
FAQ
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_13_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_13">
<span class="md-nav__icon md-icon"></span>
FAQ
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../question-and-answer/question_answer/" class="md-nav__link">
<span class="md-ellipsis">
Q & A
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../question-and-answer/faq/" class="md-nav__link">
<span class="md-ellipsis">
FAQ
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../question-and-answer/interface-compatibility/" class="md-nav__link">
<span class="md-ellipsis">
Micro Service Interface Compatibility FAQ
</span>
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#simple-synchronization-mode-producer" class="md-nav__link">
<span class="md-ellipsis">
Simple Synchronization Mode Producer:
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#nested-synchronous-call" class="md-nav__link">
<span class="md-ellipsis">
Nested synchronous call:
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#error-optimization-for-nested-synchronous-calls" class="md-nav__link">
<span class="md-ellipsis">
"Error" optimization for nested synchronous calls:
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#pure-reactive-mechanism" class="md-nav__link">
<span class="md-ellipsis">
Pure Reactive Mechanism
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#hybrid-reactive-mechanism" class="md-nav__link">
<span class="md-ellipsis">
Hybrid Reactive Mechanism
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#some-notes-about-reactive" class="md-nav__link">
<span class="md-ellipsis">
Some notes about reactive:
</span>
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-content" data-md-component="content">
<article class="md-content__inner md-typeset">
<h1>Reactive Programing</h1>
<h2 id="simple-synchronization-mode-producer">Simple Synchronization Mode Producer:</h2>
<p>Sample code:</p>
<pre><code class="language-java">@GetMapping(path = &quot;/hello/{name}&quot;)
public String hello(@PathVariable(name = &quot;name&quot;) String name){
return &quot;hello &quot; + name;
}
</code></pre>
<p>The corresponding processing flow is as follows:</p>
<p><img alt="" src="../../assets/reactive/normalSync.png" /></p>
<p>This is the traditional typical working model. The core idea is not to block network threads, and to put the business in a separate thread (to simplify the expression, only one thread is drawn in the executor)</p>
<p>In general, this mode is not a big problem.</p>
<h2 id="nested-synchronous-call">Nested synchronous call:</h2>
<p>Not all services are handled simply, you can respond directly, you may need to call other microservices.</p>
<p>Sample code:</p>
<pre><code class="language-java">public interface Intf{
String hello(String name);
}
@GetMapping(path = &quot;/hello/{name}&quot;)
public String hello(@PathVariable(name = &quot;name&quot;) String name){
return &quot;from remote: hello &quot; + intf.hello(name);
}
</code></pre>
<p>The corresponding processing flow is as follows:</p>
<p><img alt="" src="../../assets/reactive/nestedSync.png" /></p>
<p>According to the characteristics of this process, you can see the following results:</p>
<ul>
<li>
<p>Because it is a synchronous call, the calling thread of "Microservice A" is always in the blocking wait state before "Other microservices" is not answered, and does not process any other transactions.</p>
</li>
<li>
<p>When all threads in the Executor are waiting for a remote response, all new requests can only be queued in the Queue and cannot be processed. At this point, the entire system is equivalent to stop working.</p>
</li>
<li>
<p>To increase the processing power, only increase the number of threads in the Executor, and the operating system can not increase the number of threads indefinitely. The benefit of increasing the number of threads is a parabolic model. After a specific critical value, the system handles The ability will drop, and this threshold will not be too big.</p>
</li>
<li>
<p>When the remote synchronization operation is required multiple times in the business logic, the problem will be bigger than before.</p>
</li>
</ul>
<h2 id="error-optimization-for-nested-synchronous-calls">"Error" optimization for nested synchronous calls:</h2>
<p>For the previous scenario, someone would think that throwing the "Invoke producer method" into another thread pool can solve the problem, including the following:</p>
<ul>
<li>
<p>In the producer method, mark @Async, which is responsible for throwing the call to the method into other thread pools.</p>
</li>
<li>
<p>Transferring threads through business code inside the producer method</p>
</li>
</ul>
<p>Form the following process:</p>
<p><img alt="" src="../../assets/reactive/wrongSyncOptimization.png" /></p>
<p>According to the characteristics of this process, you can see the following results:</p>
<ul>
<li>
<p>"Invoke producer method" must be returned immediately, otherwise, the Executor thread will not be released</p>
</li>
<li>
<p>"Invoke producer method" must provide a new mechanism to inform the calling process of its return value, not the final return value (currently no such mechanism)</p>
</li>
<li>
<p>Although the Executor thread is released, the Customer Executor is blocked, waiting for the remote response, the blocking state of the entire system has not changed, and there is one more thread switching.</p>
</li>
<li>
<p>The mechanism seems to have the only effect is to release the executor thread, so that the executor thread has the opportunity to process other requests, which is equivalent to the concept of quarantine, the slow processing of the business does not affect other services; but the concept of serviceComb can be directly Supported, you can configure the specified business method to monopolize the new executor, so that the whole process is the same as the "nested synchronous call", the process is simpler, and you don't need to do this at the "Invoke producer method" level.</p>
</li>
</ul>
<h2 id="pure-reactive-mechanism">Pure Reactive Mechanism</h2>
<p>Sample code:</p>
<pre><code class="language-java">public interface Intf{
CompletableFuture&lt;String&gt; hello(String name);
}
@GetMapping(path = &quot;/hello/{name}&quot;)
public CompletableFuture&lt;String&gt; hello(@PathVariable(name = &quot;name&quot;) String name){
CompletableFuture&lt;String&gt; future = new CompletableFuture&lt;&gt;();
intf.hello(name).whenComplete((result, exception) -&gt; {
if (exception == null) {
future.complete(&quot;from remote: &quot; + result);
return;
}
future.completeExceptionally(exception);
});
return future;
}
</code></pre>
<p>The corresponding processing flow is as follows:</p>
<p><img alt="" src="../../assets/reactive/pureReactive.png" /></p>
<ul>
<li>
<p>Unlike traditional processes, all functions are executed in the eventloop and no thread switching is performed.</p>
</li>
<li>
<p>After the orange arrow is finished, the occupation of this thread is completed, and it will not block waiting for response. The thread can handle other tasks.</p>
</li>
<li>
<p>After receiving the remote response, the network data drive starts to take the red arrow response process</p>
</li>
<li>
<p>As long as there are tasks, the thread will not stop, the task will be executed all the time, you can make full use of the cpu resources, and will not generate redundant thread switching, to consume the CPU unnecessarily.</p>
</li>
</ul>
<p>Because in synchronous mode, a large number of threads are needed to increase the degree of concurrency, and a large number of threads bring additional consumption of thread switching.</p>
<p>The test data shows that the reactive mode only needs to consume less than half of the CPU of the synchronous mode. And can reach or exceed the tps of the synchronous mode, and the delay is lower.</p>
<h2 id="hybrid-reactive-mechanism">Hybrid Reactive Mechanism</h2>
<p>Reactive requires that all logic executed in the eventloop does not allow any blocking actions, including not limited to wait, sleep, large loops, synchronous query DB, and so on.</p>
<p>The bottom of serviceComb is based on vertx. The vertx ecosystem has reactive drivers for various rich components such as JDBC, MQ, zooKeeper, etc. Under normal circumstances, it can meet the requirements.</p>
<p>However, in some scenarios, there are indeed some synchronization operations that cannot be avoided, such as:</p>
<ul>
<li>
<p>Private security hardened redis, only provides synchronous drive</p>
</li>
<li>
<p>More complex business operations</p>
</li>
<li>
<p>......</p>
</li>
</ul>
<p>At this point, the logic of these synchronizations can be extracted and placed in the thread pool for processing, while other parts still use the reactive process.</p>
<h2 id="some-notes-about-reactive">Some notes about reactive:</h2>
<ul>
<li>Producer:</li>
</ul>
<p>* Whether the producer uses reactive and consumer to call, there is no connection</p>
<p>* When the operation return value is the CompletableFuture type, the default operation is in reactive mode. If you need to force this operation to work in thread pool mode, you need to configure it in microservice.yaml explicitly. If an operation, its schemaId is sid, operationId For asyncQuery, you need to do the following:</p>
<pre><code>servicecomb:
executors:
Provider:
sid.asyncQuery: cse.executor.groupThreadPool
</code></pre>
<p>The cse.executor.groupThreadPool here is the default thread pool built into serviceComb, which can be arbitrarily specified by the user as its custom thread pool.</p>
<ul>
<li>Consumer:</li>
</ul>
<p>* Whether the consumer uses reactive and producer how to implement, there is no connection</p>
<p>* Currently only supports transparent RPC mode, using JDK native CompletableFuture to carry this function</p>
<p>completableFuture's when, then, etc. can be used directly</p>
<p>However, the async series of completableFuture is another thread pool to perform functions. It is not recommended.</p>
<p>Support for RxJava Observable will be added later.</p>
<p>Support for AsyncRestTemplate will be added later.</p>
</article>
</div>
<script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script>
</div>
</main>
<footer class="md-footer">
<div class="md-footer-meta md-typeset">
<div class="md-footer-meta__inner md-grid">
<div class="md-copyright">
Made with
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
Material for MkDocs
</a>
</div>
</div>
</div>
</footer>
</div>
<div class="md-dialog" data-md-component="dialog">
<div class="md-dialog__inner md-typeset"></div>
</div>
<script id="__config" type="application/json">{"base": "../..", "features": [], "search": "../../assets/javascripts/workers/search.b8dbb3d2.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}}</script>
<script src="../../assets/javascripts/bundle.dd8806f2.min.js"></script>
</body>
</html>