md_doc_service_config.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  6. <meta name="generator" content="Doxygen 1.8.16"/>
  7. <meta name="viewport" content="width=device-width, initial-scale=1"/>
  8. <title>GRPC C++: Service Config in gRPC</title>
  9. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  10. <script type="text/javascript" src="jquery.js"></script>
  11. <script type="text/javascript" src="dynsections.js"></script>
  12. <link href="search/search.css" rel="stylesheet" type="text/css"/>
  13. <script type="text/javascript" src="search/searchdata.js"></script>
  14. <script type="text/javascript" src="search/search.js"></script>
  15. <link href="doxygen.css" rel="stylesheet" type="text/css" />
  16. </head>
  17. <body>
  18. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  19. <div id="titlearea">
  20. <table cellspacing="0" cellpadding="0">
  21. <tbody>
  22. <tr style="height: 56px;">
  23. <td id="projectalign" style="padding-left: 0.5em;">
  24. <div id="projectname">GRPC C++
  25. &#160;<span id="projectnumber">1.28.0</span>
  26. </div>
  27. </td>
  28. </tr>
  29. </tbody>
  30. </table>
  31. </div>
  32. <!-- end header part -->
  33. <!-- Generated by Doxygen 1.8.16 -->
  34. <script type="text/javascript">
  35. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  36. var searchBox = new SearchBox("searchBox", "search",false,'Search');
  37. /* @license-end */
  38. </script>
  39. <script type="text/javascript" src="menudata.js"></script>
  40. <script type="text/javascript" src="menu.js"></script>
  41. <script type="text/javascript">
  42. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  43. $(function() {
  44. initMenu('',true,false,'search.php','Search');
  45. $(document).ready(function() { init_search(); });
  46. });
  47. /* @license-end */</script>
  48. <div id="main-nav"></div>
  49. <!-- window showing the filter options -->
  50. <div id="MSearchSelectWindow"
  51. onmouseover="return searchBox.OnSearchSelectShow()"
  52. onmouseout="return searchBox.OnSearchSelectHide()"
  53. onkeydown="return searchBox.OnSearchSelectKey(event)">
  54. </div>
  55. <!-- iframe showing the search results (closed by default) -->
  56. <div id="MSearchResultsWindow">
  57. <iframe src="javascript:void(0)" frameborder="0"
  58. name="MSearchResults" id="MSearchResults">
  59. </iframe>
  60. </div>
  61. </div><!-- top -->
  62. <div class="PageDoc"><div class="header">
  63. <div class="headertitle">
  64. <div class="title">Service Config in gRPC </div> </div>
  65. </div><!--header-->
  66. <div class="contents">
  67. <div class="textblock"><h1><a class="anchor" id="autotoc_md219"></a>
  68. Objective</h1>
  69. <p>The service config is a mechanism that allows service owners to publish parameters to be automatically used by all clients of their service.</p>
  70. <h1><a class="anchor" id="autotoc_md220"></a>
  71. Format</h1>
  72. <p>The service config is a JSON string of the following form:</p>
  73. <div class="fragment"><div class="line">{</div>
  74. <div class="line"> // [deprecated] Load balancing policy name (case insensitive).</div>
  75. <div class="line"> // Currently, the only selectable client-side policy provided with gRPC</div>
  76. <div class="line"> // is &#39;round_robin&#39;, but third parties may add their own policies.</div>
  77. <div class="line"> // This field is optional; if unset, the default behavior is to pick</div>
  78. <div class="line"> // the first available backend. If set, the load balancing policy should be</div>
  79. <div class="line"> // supported by the client, otherwise the service config is considered</div>
  80. <div class="line"> // invalid.</div>
  81. <div class="line"> // If the policy name is set via the client API, that value overrides</div>
  82. <div class="line"> // the value specified here.</div>
  83. <div class="line"> //</div>
  84. <div class="line"> // Note that if the resolver returns at least one balancer address (as</div>
  85. <div class="line"> // opposed to backend addresses), gRPC will use grpclb (see</div>
  86. <div class="line"> // https://github.com/grpc/grpc/blob/master/doc/load-balancing.md),</div>
  87. <div class="line"> // regardless of what LB policy is requested either here or via the</div>
  88. <div class="line"> // client API.</div>
  89. <div class="line"> &#39;loadBalancingPolicy&#39;: string,</div>
  90. <div class="line"> </div>
  91. <div class="line"> // Per-method configuration. Optional.</div>
  92. <div class="line"> &#39;methodConfig&#39;: [</div>
  93. <div class="line"> {</div>
  94. <div class="line"> // The names of the methods to which this method config applies. There</div>
  95. <div class="line"> // must be at least one name. Each name entry must be unique across the</div>
  96. <div class="line"> // entire service config. If the &#39;method&#39; field is empty, then this</div>
  97. <div class="line"> // method config specifies the defaults for all methods for the specified</div>
  98. <div class="line"> // service.</div>
  99. <div class="line"> //</div>
  100. <div class="line"> // For example, let&#39;s say that the service config contains the following</div>
  101. <div class="line"> // method config entries:</div>
  102. <div class="line"> //</div>
  103. <div class="line"> // &#39;methodConfig&#39;: [</div>
  104. <div class="line"> // { &#39;name&#39;: [ { &#39;service&#39;: &#39;MyService&#39; } ] ... },</div>
  105. <div class="line"> // { &#39;name&#39;: [ { &#39;service&#39;: &#39;MyService&#39;, &#39;method&#39;: &#39;Foo&#39; } ] ... }</div>
  106. <div class="line"> // ]</div>
  107. <div class="line"> //</div>
  108. <div class="line"> // For a request for MyService/Foo, we will use the second entry, because</div>
  109. <div class="line"> // it exactly matches the service and method name.</div>
  110. <div class="line"> // For a request for MyService/Bar, we will use the first entry, because</div>
  111. <div class="line"> // it provides the default for all methods of MyService.</div>
  112. <div class="line"> &#39;name&#39;: [</div>
  113. <div class="line"> {</div>
  114. <div class="line"> // RPC service name. Required.</div>
  115. <div class="line"> // If using gRPC with protobuf as the IDL, then this will be of</div>
  116. <div class="line"> // the form &quot;pkg.service_name&quot;, where &quot;pkg&quot; is the package name</div>
  117. <div class="line"> // defined in the proto file.</div>
  118. <div class="line"> &#39;service&#39;: string,</div>
  119. <div class="line"> </div>
  120. <div class="line"> // RPC method name. Optional (see above).</div>
  121. <div class="line"> &#39;method&#39;: string,</div>
  122. <div class="line"> }</div>
  123. <div class="line"> ],</div>
  124. <div class="line"> </div>
  125. <div class="line"> // Optional. Whether RPCs sent to this method should wait until the</div>
  126. <div class="line"> // connection is ready by default. If false, the RPC will abort</div>
  127. <div class="line"> // immediately if there is a transient failure connecting to the server.</div>
  128. <div class="line"> // Otherwise, gRPC will attempt to connect until the deadline is</div>
  129. <div class="line"> // exceeded.</div>
  130. <div class="line"> //</div>
  131. <div class="line"> // The value specified via the gRPC client API will override the value</div>
  132. <div class="line"> // set here. However, note that setting the value in the client API will</div>
  133. <div class="line"> // also affect transient errors encountered during name resolution,</div>
  134. <div class="line"> // which cannot be caught by the value here, since the service config</div>
  135. <div class="line"> // is obtained by the gRPC client via name resolution.</div>
  136. <div class="line"> &#39;waitForReady&#39;: bool,</div>
  137. <div class="line"> </div>
  138. <div class="line"> // Optional. The default timeout in seconds for RPCs sent to this method.</div>
  139. <div class="line"> // This can be overridden in code. If no reply is received in the</div>
  140. <div class="line"> // specified amount of time, the request is aborted and a</div>
  141. <div class="line"> // deadline-exceeded error status is returned to the caller.</div>
  142. <div class="line"> //</div>
  143. <div class="line"> // The actual deadline used will be the minimum of the value specified</div>
  144. <div class="line"> // here and the value set by the application via the gRPC client API.</div>
  145. <div class="line"> // If either one is not set, then the other will be used.</div>
  146. <div class="line"> // If neither is set, then the request has no deadline.</div>
  147. <div class="line"> //</div>
  148. <div class="line"> // The format of the value is that of the &#39;Duration&#39; type defined here:</div>
  149. <div class="line"> // https://developers.google.com/protocol-buffers/docs/proto3#json</div>
  150. <div class="line"> &#39;timeout&#39;: string,</div>
  151. <div class="line"> </div>
  152. <div class="line"> // Optional. The maximum allowed payload size for an individual request</div>
  153. <div class="line"> // or object in a stream (client-&gt;server) in bytes. The size which is</div>
  154. <div class="line"> // measured is the serialized, uncompressed payload in bytes. This</div>
  155. <div class="line"> // applies both to streaming and non-streaming requests.</div>
  156. <div class="line"> //</div>
  157. <div class="line"> // The actual value used is the minimum of the value specified here and</div>
  158. <div class="line"> // the value set by the application via the gRPC client API.</div>
  159. <div class="line"> // If either one is not set, then the other will be used.</div>
  160. <div class="line"> // If neither is set, then the built-in default is used.</div>
  161. <div class="line"> //</div>
  162. <div class="line"> // If a client attempts to send an object larger than this value, it</div>
  163. <div class="line"> // will not be sent and the client will see an error.</div>
  164. <div class="line"> // Note that 0 is a valid value, meaning that the request message must</div>
  165. <div class="line"> // be empty.</div>
  166. <div class="line"> &#39;maxRequestMessageBytes&#39;: number,</div>
  167. <div class="line"> </div>
  168. <div class="line"> // Optional. The maximum allowed payload size for an individual response</div>
  169. <div class="line"> // or object in a stream (server-&gt;client) in bytes. The size which is</div>
  170. <div class="line"> // measured is the serialized, uncompressed payload in bytes. This</div>
  171. <div class="line"> // applies both to streaming and non-streaming requests.</div>
  172. <div class="line"> //</div>
  173. <div class="line"> // The actual value used is the minimum of the value specified here and</div>
  174. <div class="line"> // the value set by the application via the gRPC client API.</div>
  175. <div class="line"> // If either one is not set, then the other will be used.</div>
  176. <div class="line"> // If neither is set, then the built-in default is used.</div>
  177. <div class="line"> //</div>
  178. <div class="line"> // If a server attempts to send an object larger than this value, it</div>
  179. <div class="line"> // will not be sent, and the client will see an error.</div>
  180. <div class="line"> // Note that 0 is a valid value, meaning that the response message must</div>
  181. <div class="line"> // be empty.</div>
  182. <div class="line"> &#39;maxResponseMessageBytes&#39;: number</div>
  183. <div class="line"> }</div>
  184. <div class="line"> ]</div>
  185. <div class="line">}</div>
  186. </div><!-- fragment --><p>Note that new per-method parameters may be added in the future as new functionality is introduced.</p>
  187. <h1><a class="anchor" id="autotoc_md221"></a>
  188. Architecture</h1>
  189. <p>A service config is associated with a server name. The <a class="el" href="naming_8md.html">name resolver</a> plugin, when asked to resolve a particular server name, will return both the resolved addresses and the service config.</p>
  190. <p>TODO(roth): Design how the service config will be encoded in DNS.</p>
  191. <h1><a class="anchor" id="autotoc_md222"></a>
  192. APIs</h1>
  193. <p>The service config is used in the following APIs:</p>
  194. <ul>
  195. <li>In the resolver API, used by resolver plugins to return the service config to the gRPC client.</li>
  196. <li>In the gRPC client API, where users can query the channel to obtain the service config associated with the channel (for debugging purposes).</li>
  197. <li>In the gRPC client API, where users can set the service config explicitly. This is intended for use in unit tests. </li>
  198. </ul>
  199. </div></div><!-- contents -->
  200. </div><!-- PageDoc -->
  201. <!-- start footer part -->
  202. <hr class="footer"/><address class="footer"><small>
  203. Generated on Tue Apr 7 2020 11:33:59 for GRPC C++ by &#160;<a href="http://www.doxygen.org/index.html">
  204. <img class="footer" src="doxygen.png" alt="doxygen"/>
  205. </a> 1.8.16
  206. </small></address>
  207. </body>
  208. </html>