mirror of
https://github.com/corda/corda.git
synced 2024-12-23 14:52:29 +00:00
377 lines
20 KiB
HTML
377 lines
20 KiB
HTML
|
|
|
|
<!DOCTYPE html>
|
|
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
|
|
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
|
|
<head>
|
|
<meta charset="utf-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<title>Client RPC — R3 Corda latest documentation</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="_static/css/custom.css" type="text/css" />
|
|
|
|
|
|
|
|
|
|
|
|
<link rel="top" title="R3 Corda latest documentation" href="index.html"/>
|
|
<link rel="next" title="Networking and messaging" href="messaging.html"/>
|
|
<link rel="prev" title="The CorDapp Template" href="tutorial-cordapp.html"/>
|
|
|
|
|
|
<script src="_static/js/modernizr.min.js"></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">
|
|
<div class="wy-side-scroll">
|
|
<div class="wy-side-nav-search">
|
|
|
|
|
|
|
|
|
|
<a href="index.html" class="icon icon-home"> R3 Corda
|
|
|
|
|
|
|
|
</a>
|
|
|
|
|
|
|
|
|
|
<div class="version">
|
|
latest
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div role="search">
|
|
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
|
|
<input type="text" name="q" placeholder="Search docs" />
|
|
<input type="hidden" name="check_keywords" value="yes" />
|
|
<input type="hidden" name="area" value="default" />
|
|
</form>
|
|
</div>
|
|
|
|
|
|
<br>
|
|
<a href="api/index.html">API reference</a>
|
|
|
|
</div>
|
|
|
|
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
|
|
|
|
|
|
|
|
<p class="caption"><span class="caption-text">Getting started</span></p>
|
|
<ul>
|
|
<li class="toctree-l1"><a class="reference internal" href="inthebox.html">What’s included?</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="getting-set-up.html">Getting set up</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="getting-set-up-fault-finding.html">Getting set up: troubleshooting</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="running-the-demos.html">Running the demos</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="CLI-vs-IDE.html">CLI vs IDE</a></li>
|
|
</ul>
|
|
<p class="caption"><span class="caption-text">Key concepts</span></p>
|
|
<ul>
|
|
<li class="toctree-l1"><a class="reference internal" href="data-model.html">Data model</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="transaction-data-types.html">Data types</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="merkle-trees.html">Transaction tear-offs</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="consensus.html">Consensus model</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="clauses.html">Clauses key concepts</a></li>
|
|
</ul>
|
|
<p class="caption"><span class="caption-text">CorDapps</span></p>
|
|
<ul>
|
|
<li class="toctree-l1"><a class="reference internal" href="creating-a-cordapp.html">CorDapps Background</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="creating-a-cordapp.html#gradle-plugins-for-cordapps">Gradle plugins for CorDapps</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="tutorial-cordapp.html">The CorDapp Template</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="tutorial-cordapp.html#building-the-cordapp-template">Building the CorDapp template</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="tutorial-cordapp.html#running-the-sample-cordapp">Running the Sample CorDapp</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="tutorial-cordapp.html#using-the-sample-cordapp">Using the sample CorDapp</a></li>
|
|
</ul>
|
|
<p class="caption"><span class="caption-text">The Corda node</span></p>
|
|
<ul class="current">
|
|
<li class="toctree-l1 current"><a class="current reference internal" href="#">Client RPC</a><ul>
|
|
<li class="toctree-l2"><a class="reference internal" href="#security">Security</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="#observables">Observables</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="#versioning">Versioning</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="#thread-safety">Thread safety</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="#error-handling">Error handling</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="#wire-protocol">Wire protocol</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="#registering-classes-with-rpc-kryo">Registering classes with RPC Kryo</a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="toctree-l1"><a class="reference internal" href="messaging.html">Networking and messaging</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="persistence.html">Persistence</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="node-administration.html">Node administration</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="corda-configuration-file.html">Node configuration</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="corda-plugins.html">The Corda plugin framework</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="node-services.html">Brief introduction to the node services</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="node-explorer.html">Node Explorer</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="permissioning.html">Network permissioning</a></li>
|
|
</ul>
|
|
<p class="caption"><span class="caption-text">Tutorials</span></p>
|
|
<ul>
|
|
<li class="toctree-l1"><a class="reference internal" href="tutorial-contract.html">Writing a contract</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="tutorial-contract-clauses.html">Writing a contract using clauses</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="tutorial-test-dsl.html">Writing a contract test</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="tutorial-integration-testing.html">Integration Test Tutorial</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="tutorial-clientrpc-api.html">Client RPC API tutorial</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="tutorial-building-transactions.html">Building Transactions</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="flow-state-machines.html">Writing flows</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="flow-testing.html">Writing flow tests</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="running-a-notary.html">Running a notary service</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="using-a-notary.html">Using a notary service</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="oracles.html">Writing oracle services</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="oracles.html#implementing-an-oracle-with-continuously-varying-data">Implementing an oracle with continuously varying data</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="oracles.html#using-an-oracle">Using an oracle</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="tutorial-attachments.html">Using attachments</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="event-scheduling.html">Event scheduling</a></li>
|
|
</ul>
|
|
<p class="caption"><span class="caption-text">Other</span></p>
|
|
<ul>
|
|
<li class="toctree-l1"><a class="reference internal" href="network-simulator.html">Network Simulator</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="initial-margin-agreement.html">Initial margin agreements</a></li>
|
|
</ul>
|
|
<p class="caption"><span class="caption-text">Component library</span></p>
|
|
<ul>
|
|
<li class="toctree-l1"><a class="reference internal" href="contract-catalogue.html">Contract catalogue</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="contract-irs.html">Interest rate swaps</a></li>
|
|
</ul>
|
|
<p class="caption"><span class="caption-text">Appendix</span></p>
|
|
<ul>
|
|
<li class="toctree-l1"><a class="reference internal" href="loadtesting.html">Load testing</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="setting-up-a-corda-network.html">Introduction - What is a corda network?</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="setting-up-a-corda-network.html#setting-up-your-own-network">Setting up your own network</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="secure-coding-guidelines.html">Secure coding guidelines</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="release-process.html">Release process</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="release-process.html#steps-to-cut-a-release">Steps to cut a release</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="release-notes.html">Release notes</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="codestyle.html">Code style guide</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="building-the-docs.html">Building the documentation</a></li>
|
|
</ul>
|
|
<p class="caption"><span class="caption-text">Glossary</span></p>
|
|
<ul>
|
|
<li class="toctree-l1"><a class="reference internal" href="glossary.html">Glossary</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="top navigation">
|
|
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
|
<a href="index.html">R3 Corda</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="index.html">Docs</a> »</li>
|
|
|
|
<li>Client RPC</li>
|
|
<li class="wy-breadcrumbs-aside">
|
|
|
|
|
|
<a href="_sources/clientrpc.txt" rel="nofollow"> View page source</a>
|
|
|
|
|
|
</li>
|
|
</ul>
|
|
<hr/>
|
|
</div>
|
|
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
|
|
<div itemprop="articleBody">
|
|
|
|
<div class="section" id="client-rpc">
|
|
<h1>Client RPC<a class="headerlink" href="#client-rpc" title="Permalink to this headline">¶</a></h1>
|
|
<p>There are multiple ways to interact with a node from a <em>client program</em>, but if your client is written in a JVM
|
|
compatible language the easiest way to do so is using the client library. The library connects to your running
|
|
node using a message queue protocol and then provides a simple RPC interface to interact with it. You make calls
|
|
on a Java object as normal, and the marshalling back and forth is handled for you.</p>
|
|
<p>The starting point for the client library is the <a class="reference external" href="api/net.corda.client/-corda-r-p-c-client/index.html">CordaRPCClient</a> class. This provides a <code class="docutils literal"><span class="pre">proxy</span></code> method that
|
|
returns an implementation of the <a class="reference external" href="api/net.corda.node.services.messaging/-corda-r-p-c-ops/index.html">CordaRPCOps</a> interface. A timeout parameter can be specified, and observables that
|
|
are returned by RPCs can be subscribed to in order to receive an ongoing stream of updates from the node. More
|
|
detail on how to use this is provided in the docs for the proxy method.</p>
|
|
<div class="admonition warning">
|
|
<p class="first admonition-title">Warning</p>
|
|
<p class="last">The returned object is somewhat expensive to create and consumes a small amount of server side
|
|
resources. When you’re done with it, cast it to <code class="docutils literal"><span class="pre">Closeable</span></code> or <code class="docutils literal"><span class="pre">AutoCloseable</span></code> and close it. Don’t create
|
|
one for every call you make - create a proxy and reuse it.</p>
|
|
</div>
|
|
<p>For a brief tutorial on how one can use the RPC API see <a class="reference internal" href="tutorial-clientrpc-api.html"><span class="doc">Client RPC API tutorial</span></a>.</p>
|
|
<div class="section" id="security">
|
|
<h2>Security<a class="headerlink" href="#security" title="Permalink to this headline">¶</a></h2>
|
|
<p>Users wanting to use the RPC library are first required to authenticate themselves with the node using a valid username
|
|
and password. These are specified in the configuration file. Each user can be configured with a set of permissions which
|
|
the RPC can use for fine-grain access control.</p>
|
|
</div>
|
|
<div class="section" id="observables">
|
|
<h2>Observables<a class="headerlink" href="#observables" title="Permalink to this headline">¶</a></h2>
|
|
<p>The RPC system handles observables in a special way. When a method returns an observable, whether directly or
|
|
as a sub-object of the response object graph, an observable is created on the client to match the one on the
|
|
server. Objects emitted by the server-side observable are pushed onto a queue which is then drained by the client.
|
|
The returned observable may even emit object graphs with even more observables in them, and it all works as you
|
|
would expect.</p>
|
|
<p>This feature comes with a cost: the server must queue up objects emitted by the server-side observable until you
|
|
download them. Therefore RPCs that use this feature are marked with the <code class="docutils literal"><span class="pre">@RPCReturnsObservables</span></code> annotation, and
|
|
you are expected to subscribe to all the observables returned. If you don’t want an observable then subscribe
|
|
then unsubscribe immediately to clear the buffers and indicate that you aren’t interested. If your app quits then
|
|
server side resources will be freed automatically.</p>
|
|
<p>When all the observables returned by an RPC are unsubscribed on the client side, that unsubscription propagates
|
|
through to the server where the corresponding server-side observables are also unsubscribed.</p>
|
|
<div class="admonition warning">
|
|
<p class="first admonition-title">Warning</p>
|
|
<p class="last">If you leak an observable or proxy on the client side and it gets garbage collected, you will get
|
|
a warning printed to the logs and the proxy will be closed for you. But don’t rely on this, as garbage
|
|
collection is non-deterministic.</p>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="versioning">
|
|
<h2>Versioning<a class="headerlink" href="#versioning" title="Permalink to this headline">¶</a></h2>
|
|
<p>The client RPC protocol is versioned with a simple incrementing integer. When a proxy is created the server is
|
|
queried for its protocol version, and you can specify your minimum requirement. Methods added in later versions
|
|
are tagged with the <code class="docutils literal"><span class="pre">@RPCSinceVersion</span></code> annotation. If you try to use a method that the server isn’t advertising
|
|
support of, an <code class="docutils literal"><span class="pre">UnsupportedOperationException</span></code> is thrown. If you want to know the version of the server, just
|
|
use the <code class="docutils literal"><span class="pre">protocolVersion</span></code> property (i.e. <code class="docutils literal"><span class="pre">getProtocolVersion</span></code> in Java).</p>
|
|
</div>
|
|
<div class="section" id="thread-safety">
|
|
<h2>Thread safety<a class="headerlink" href="#thread-safety" title="Permalink to this headline">¶</a></h2>
|
|
<p>A proxy is thread safe, blocking, and will only allow a single RPC to be in flight at once. Any observables that
|
|
are returned and you subscribe to will have objects emitted on a background thread. Observables returned as part
|
|
of one RPC and observables returned from another may have their callbacks invoked in parallel, but observables
|
|
returned as part of the same specific RPC invocation are processed serially and will not be invoked in parallel.</p>
|
|
<p>If you want to make multiple calls to the server in parallel you can do that by creating multiple proxies, but
|
|
be aware that the server itself may <em>not</em> process your work in parallel even if you make your requests that way.</p>
|
|
</div>
|
|
<div class="section" id="error-handling">
|
|
<h2>Error handling<a class="headerlink" href="#error-handling" title="Permalink to this headline">¶</a></h2>
|
|
<p>If something goes wrong with the RPC infrastructure itself, an <code class="docutils literal"><span class="pre">RPCException</span></code> is thrown. If you call a method that
|
|
requires a higher version of the protocol than the server supports, <code class="docutils literal"><span class="pre">UnsupportedOperationException</span></code> is thrown.
|
|
Otherwise, if the server implementation throws an exception, that exception is serialised and rethrown on the client
|
|
side as if it was thrown from inside the called RPC method. These exceptions can be caught as normal.</p>
|
|
</div>
|
|
<div class="section" id="wire-protocol">
|
|
<h2>Wire protocol<a class="headerlink" href="#wire-protocol" title="Permalink to this headline">¶</a></h2>
|
|
<p>The client RPC wire protocol is not currently documented. To use it you must use the client library provided.
|
|
This is likely to change in a future release.</p>
|
|
</div>
|
|
<div class="section" id="registering-classes-with-rpc-kryo">
|
|
<h2>Registering classes with RPC Kryo<a class="headerlink" href="#registering-classes-with-rpc-kryo" title="Permalink to this headline">¶</a></h2>
|
|
<p>In the present implementation of the node we use Kryo to generate the <em>on the wire</em> representation of contracts states
|
|
or any other classes that form part of the RPC arguments or response. To avoid the RPC interface being wide open to all
|
|
classes on the classpath, Cordapps will currently have to register any classes or custom serialisers they require with Kryo
|
|
if they are not one of those registered by default in <code class="docutils literal"><span class="pre">RPCKryo</span></code> via the plugin architecture. See <a class="reference internal" href="creating-a-cordapp.html"><span class="doc">CorDapps Background</span></a>.
|
|
This will require some familiarity with Kryo. An example is shown in <a class="reference internal" href="tutorial-clientrpc-api.html"><span class="doc">Client RPC API tutorial</span></a>.</p>
|
|
<div class="admonition warning">
|
|
<p class="first admonition-title">Warning</p>
|
|
<p class="last">We will be replacing the use of Kryo in RPC with a stable message format and this will mean that this plugin
|
|
customisation point will either go away completely or change.</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
<footer>
|
|
|
|
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
|
|
|
|
<a href="messaging.html" class="btn btn-neutral float-right" title="Networking and messaging" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
|
|
|
|
|
|
<a href="tutorial-cordapp.html" class="btn btn-neutral" title="The CorDapp Template" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a>
|
|
|
|
</div>
|
|
|
|
|
|
<hr/>
|
|
|
|
<div role="contentinfo">
|
|
<p>
|
|
© Copyright 2016, R3 Limited.
|
|
|
|
</p>
|
|
</div>
|
|
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
|
|
|
|
</footer>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
var DOCUMENTATION_OPTIONS = {
|
|
URL_ROOT:'./',
|
|
VERSION:'latest',
|
|
COLLAPSE_INDEX:false,
|
|
FILE_SUFFIX:'.html',
|
|
HAS_SOURCE: true
|
|
};
|
|
</script>
|
|
<script type="text/javascript" src="_static/jquery.js"></script>
|
|
<script type="text/javascript" src="_static/underscore.js"></script>
|
|
<script type="text/javascript" src="_static/doctools.js"></script>
|
|
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript" src="_static/js/theme.js"></script>
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
jQuery(function () {
|
|
SphinxRtdTheme.StickyNav.enable();
|
|
});
|
|
</script>
|
|
|
|
|
|
</body>
|
|
</html> |