iamqp
Version:
RabbitMQ wrapper for NodeJS with several produce(reply)/consume scenarios
2,173 lines (590 loc) • 28.9 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Common - Documentation</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav>
<li class="nav-link nav-home-link"><a href="index.html">Home</a></li><li class="nav-heading">Classes</li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Common.html">Common</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Common.html#_commonPublishPreparations">_commonPublishPreparations</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Common.html#_emitAndDispatchError">_emitAndDispatchError</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Common.html#_logData">_logData</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Common.html#_messageDispatcherWrapper">_messageDispatcherWrapper</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Common.html#_parseConsumedMessage">_parseConsumedMessage</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Common.html#_preparePublishingMessage">_preparePublishingMessage</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Common.html#closeConnection">closeConnection</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Common.html#getEventer">getEventer</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Common.html#isReady">isReady</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Common.html#openConnection">openConnection</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Common.html#toString">toString</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="ConsoleLogger.html">ConsoleLogger</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="ConsoleLogger.html#error">error</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="ConsoleLogger.html#info">info</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="ConsoleLogger.html#log">log</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="ConsoleLogger.html#warn">warn</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="FanoutConsumer.html">FanoutConsumer</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="FanoutProducer.html">FanoutProducer</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="FanoutProducer.html#fanout">fanout</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="PlainConsumer.html">PlainConsumer</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="PlainProducer.html">PlainProducer</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="PlainProducer.html#publish">publish</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="RpcClient.html">RpcClient</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="RpcClient.html#callRemote">callRemote</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="RpcServer.html">RpcServer</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="RpcServer.html#respond">respond</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="UUIDv4.html">UUIDv4</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="UUIDv4.html#generate">generate</a></span></li><li class="nav-heading"><a href="global.html">Globals</a></li>
</nav>
<div id="main">
<h1 class="page-title">Common</h1>
<section>
<header>
<h2>
Common
</h2>
</header>
<article>
<div class="container-overview">
<div class="section-method">
<h4 class="name" id="Common"><span class="type-signature"></span>new Common<span class="signature">(amqpUri, channelName, configuration<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="common.js.html">common.js</a>, <a href="common.js.html#line63">line 63</a>
</li></ul></dd>
</dl>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>amqpUri</code></td>
<td class="type">
<span class="param-type"><code><a href="global.html#AmqpURI">AmqpURI</a></code></span>
</td>
<td class="attributes">
</td>
<td class="description last">
</td>
</tr>
<tr>
<td class="name"><code>channelName</code></td>
<td class="type">
<span class="param-type"><code><a href="global.html#ChannelName">ChannelName</a></code></span>
</td>
<td class="attributes">
</td>
<td class="description last">
</td>
</tr>
<tr>
<td class="name"><code>configuration</code></td>
<td class="type">
<span class="param-type"><code><a href="global.html#Configuration">Configuration</a></code></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">
</td>
</tr>
</tbody>
</table>
</div>
</div>
<h3 class="subsection-title">Members</h3>
<div class="section-members">
<h4 class="name" id="_configuration"><span class="type-signature">(protected) </span>_configuration<span class="type-signature"> :Object</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="common.js.html">common.js</a>, <a href="common.js.html#line123">line 123</a>
</li></ul></dd>
</dl>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type"><code>Object</code></span>
</li>
</ul>
</div>
<div class="section-members">
<h4 class="name" id="_consoleLogger"><span class="type-signature">(protected) </span>_consoleLogger<span class="type-signature"> :<a href="ConsoleLogger.html">ConsoleLogger</a></span></h4>
<div class="description">
<p>Internal instance to log messages.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="common.js.html">common.js</a>, <a href="common.js.html#line77">line 77</a>
</li></ul></dd>
</dl>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type"><code><a href="ConsoleLogger.html">ConsoleLogger</a></code></span>
</li>
</ul>
</div>
<div class="section-members">
<h4 class="name" id="_E"><span class="type-signature">(protected) </span>_E<span class="type-signature"> :*|EventEmitter</span></h4>
<div class="description">
<p>Used to emit messages and statues.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="common.js.html">common.js</a>, <a href="common.js.html#line84">line 84</a>
</li></ul></dd>
</dl>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type"><code>*</code></span>
|
<span class="param-type"><code>EventEmitter</code></span>
</li>
</ul>
</div>
<div class="section-members">
<h4 class="name" id="_isReady"><span class="type-signature">(protected) </span>_isReady<span class="type-signature"> :boolean</span></h4>
<div class="description">
<p>Internal flag for signaling of the connection if ready.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="common.js.html">common.js</a>, <a href="common.js.html#line99">line 99</a>
</li></ul></dd>
</dl>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type"><code>boolean</code></span>
</li>
</ul>
</div>
<div class="section-members">
<h4 class="name" id="_name"><span class="type-signature">(protected) </span>_name<span class="type-signature"> :string</span></h4>
<div class="description">
<p>Name associated with this instance - displayed in the logs.
Each instance should override this with some relevant name.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="common.js.html">common.js</a>, <a href="common.js.html#line70">line 70</a>
</li></ul></dd>
</dl>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type"><code>string</code></span>
</li>
</ul>
</div>
<h3 class="subsection-title">Methods</h3>
<div class="section-method">
<h4 class="name" id="_commonPublishPreparations"><span class="type-signature"></span>_commonPublishPreparations<span class="signature">(contentToPublish)</span><span class="type-signature"> → {*|null}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="common.js.html">common.js</a>, <a href="common.js.html#line394">line 394</a>
</li></ul></dd>
</dl>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>contentToPublish</code></td>
<td class="type">
<span class="param-type"><code>number</code></span>
|
<span class="param-type"><code>string</code></span>
|
<span class="param-type"><code>boolean</code></span>
|
<span class="param-type"><code>Object</code></span>
|
<span class="param-type"><code>Array</code></span>
</td>
<td class="description last">
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>*</code></span>
|
<span class="param-type"><code>null</code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="_emitAndDispatchError"><span class="type-signature">(protected) </span>_emitAndDispatchError<span class="signature">(errorMessage)</span><span class="type-signature"></span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="common.js.html">common.js</a>, <a href="common.js.html#line252">line 252</a>
</li></ul></dd>
</dl>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>errorMessage</code></td>
<td class="type">
<span class="param-type"><code>string</code></span>
</td>
<td class="description last">
</td>
</tr>
</tbody>
</table>
</div>
<div class="section-method">
<h4 class="name" id="_logData"><span class="type-signature">(protected) </span>_logData<span class="signature">(data, description)</span><span class="type-signature"></span></h4>
<div class="description">
<p>Log the data that was received or send in the channels.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="common.js.html">common.js</a>, <a href="common.js.html#line421">line 421</a>
</li></ul></dd>
</dl>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>data</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
|
<span class="param-type"><code>Buffer</code></span>
</td>
<td class="description last">
</td>
</tr>
<tr>
<td class="name"><code>description</code></td>
<td class="type">
<span class="param-type"><code>string</code></span>
</td>
<td class="description last">
<p>some additional information to be logged with the data</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="section-method">
<h4 class="name" id="_messageDispatcherWrapper"><span class="type-signature">(protected) </span>_messageDispatcherWrapper<span class="signature">(logType, message)</span><span class="type-signature"></span></h4>
<div class="description">
<p>Wrapper for common message handling.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="common.js.html">common.js</a>, <a href="common.js.html#line244">line 244</a>
</li></ul></dd>
</dl>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>logType</code></td>
<td class="type">
<span class="param-type"><code>'log'</code></span>
|
<span class="param-type"><code>'info'</code></span>
|
<span class="param-type"><code>'warn'</code></span>
|
<span class="param-type"><code>'error'</code></span>
</td>
<td class="description last">
<p>one of <code>log, info, warn, error</code></p>
</td>
</tr>
<tr>
<td class="name"><code>message</code></td>
<td class="type">
<span class="param-type"><code>string</code></span>
</td>
<td class="description last">
<p>message to print</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="section-method">
<h4 class="name" id="_parseConsumedMessage"><span class="type-signature">(protected) </span>_parseConsumedMessage<span class="signature">(message)</span><span class="type-signature"> → {number|string|Object|boolean|Array|null}</span></h4>
<div class="description">
<p>Parse the message that was consumed.
The parsing tries parsing via the <code>JSON.parse</code>.
If this fails, it just tries to return a string representation.
It can parse:</p>
<ul>
<li>number</li>
<li>string</li>
<li>plain Object</li>
<li>Array</li>
<li>boolean</li>
</ul>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="common.js.html">common.js</a>, <a href="common.js.html#line345">line 345</a>
</li></ul></dd>
</dl>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>message</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>as received by the consumer; it expects a property <code>content</code> of type Buffer</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>number</code></span>
|
<span class="param-type"><code>string</code></span>
|
<span class="param-type"><code>Object</code></span>
|
<span class="param-type"><code>boolean</code></span>
|
<span class="param-type"><code>Array</code></span>
|
<span class="param-type"><code>null</code></span>
</dd>
</dl>
<div class="param-desc">
<p>null is returned if the message was not parsed</p>
</div>
</div>
</div>
<div class="section-method">
<h4 class="name" id="_preparePublishingMessage"><span class="type-signature">(protected) </span>_preparePublishingMessage<span class="signature">(message)</span><span class="type-signature"> → {Buffer|null}</span></h4>
<div class="description">
<p>Prepare the data to be published.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="common.js.html">common.js</a>, <a href="common.js.html#line371">line 371</a>
</li></ul></dd>
</dl>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>message</code></td>
<td class="type">
<span class="param-type"><code>string</code></span>
|
<span class="param-type"><code>Object</code></span>
|
<span class="param-type"><code>number</code></span>
|
<span class="param-type"><code>boolean</code></span>
|
<span class="param-type"><code>Array</code></span>
</td>
<td class="description last">
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Buffer</code></span>
|
<span class="param-type"><code>null</code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="closeConnection"><span class="type-signature"></span>closeConnection<span class="signature">()</span><span class="type-signature"> → {boolean}</span></h4>
<div class="description">
<p>Close the connection.
The client will not preform an automatic reconnect when this is called.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="common.js.html">common.js</a>, <a href="common.js.html#line457">line 457</a>
</li></ul></dd>
</dl>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>boolean</code></span>
</dd>
</dl>
<div class="param-desc">
<p>false if there was an error</p>
</div>
</div>
</div>
<div class="section-method">
<h4 class="name" id="getEventer"><span class="type-signature"></span>getEventer<span class="signature">()</span><span class="type-signature"> → {EventEmitter}</span></h4>
<div class="description">
<p>Get the EventEmitter that emits messages and errors.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="common.js.html">common.js</a>, <a href="common.js.html#line490">line 490</a>
</li></ul></dd>
</dl>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>EventEmitter</code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="isReady"><span class="type-signature"></span>isReady<span class="signature">()</span><span class="type-signature"> → {boolean}</span></h4>
<div class="description">
<p>Check if the connection is operational.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="common.js.html">common.js</a>, <a href="common.js.html#line482">line 482</a>
</li></ul></dd>
</dl>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>boolean</code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="openConnection"><span class="type-signature"></span>openConnection<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
<p>Open the connection.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="common.js.html">common.js</a>, <a href="common.js.html#line472">line 472</a>
</li></ul></dd>
</dl>
</div>
<div class="section-method">
<h4 class="name" id="toString"><span class="type-signature"></span>toString<span class="signature">()</span><span class="type-signature"> → {string}</span></h4>
<div class="description">
<p>Get a string representation of this instance.
If prints the keys and values of all non-private members that are primitives.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="common.js.html">common.js</a>, <a href="common.js.html#line500">line 500</a>
</li></ul></dd>
</dl>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>string</code></span>
</dd>
</dl>
</div>
</div>
</article>
</section>
</div>
<br class="clear">
<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.2</a> on Sun Aug 04 2019 22:10:47 GMT+0200 (Central European Summer Time) using the Minami theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/linenumber.js"></script>
</body>
</html>