UNPKG

@frankvdb/node-red-contrib-amqp

Version:
279 lines (262 loc) 11.5 kB
<script type="text/javascript"> RED.nodes.registerType('amqp-in', { category: 'AMQP', color: '#98b886', defaults: { name: { value: '' }, broker: { value: '', type: 'amqp-broker' }, prefetch: { value: 0 }, reconnectOnError: { value: false }, noAck: { value: true }, exchangeName: { value: '' }, exchangeType: { value: 'topic' }, exchangeRoutingKey: { value: '' }, showExchangeConfiguration: { value: false }, autoCreateExchangeBindings: { value: false }, exchangeDurable: { value: true }, queueName: { value: '' }, queueType: { value: 'quorum'}, queueExclusive: { value: true }, queueDurable: { value: false }, queueAutoDelete: { value: false }, autoCreateQueue: { value: false }, queueArguments: { value: '{}' }, headers: { value: '{}' }, }, inputs: 1, outputs: 1, icon: 'rabbitmq.png', label: function () { if (this.name) { return this.name } const name = this.exchangeName const colon = name && this.exchangeRoutingKey ? ': ' : '' const label = name + colon + this.exchangeRoutingKey return label || 'amqp-in' }, oneditprepare: function () { $('#node-input-headers').typedInput({ type: 'json', types: ['json'], }) $('#node-input-queueArguments').typedInput({ type: 'json', types: ['json'], }) function updateExchangeFields() { const exchangeType = $('#node-input-exchangeType').val() const showExchangeConfiguration = $('#node-input-showExchangeConfiguration').is(':checked') $('.exchange-configuration-section').toggle(showExchangeConfiguration) if (!showExchangeConfiguration || ['fanout', 'headers'].includes(exchangeType)) { $('.routing-key-form-input').hide() } else { $('.routing-key-form-input').show() } if (showExchangeConfiguration && ['headers'].includes(exchangeType)) { $('.headers-form-input').show() } else { $('.headers-form-input').hide() } } $('#node-input-exchangeType').change(function (e) { updateExchangeFields() }) $('#node-input-showExchangeConfiguration').change(function (e) { updateExchangeFields() }) updateExchangeFields() $("#node-input-queueType").typedInput({ types: [ { value: "quorum", options: [ { value: "quorum", label: "Quorum"}, { value: "classic", label: "Classic"} ] } ] }) }, }) </script> <style> div.wide-label-amqp-in label { width: 30% !important; } div.wide-label-amqp-in input { width: 65% !important; } </style> <script type="text/html" data-template-name="amqp-in"> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i>&nbsp;&nbsp;Name</label> <input type="text" id="node-input-name" placeholder="Leave blank to use exchange name"> </div> <div class="form-row"> <label for="node-input-broker"><i class="fa fa-globe"></i>&nbsp;&nbsp;Broker</label> <input type="text" id="node-input-broker" placeholder="AMQP Broker"> </div> <div class="form-row"> <label for="node-input-prefetch"><i class="fa fa-filter"></i>&nbsp;&nbsp;Prefetch</label> <input type="text" id="node-input-prefetch" placeholder="0 for no prefetch restriction"> </div> <div class="form-row"> <label>&nbsp;&nbsp;</label> <input id="node-input-reconnectOnError" style="width:20px; vertical-align:baseline; margin-right:5px;" type="checkbox"> <label for="node-input-reconnectOnError" style="width:auto; margin-top:7px;">reconnectOnError</label> </div> <div class="form-row"> <label>&nbsp;</label> <input style="width:20px; vertical-align:baseline; margin-right:5px;" type="checkbox" id="node-input-noAck"> <label style="width:auto; margin-top:7px;" for="node-input-noAck">noAck</label> </div> <div class="form-tips"> <i class="fa fa-info-circle"></i> If noAck is unchecked here the message will be acknowledged upon successful receipt <em>before</em> it is sent through the output. If you need more control over when acknowledgment happens, use the <strong>amqp-in-manual-ack</strong> node. </div> <hr> <div class="form-row"> <label for="node-input-showExchangeConfiguration" style="width:100%; font-weight:700; margin-bottom:0;"> <input id="node-input-showExchangeConfiguration" type="checkbox" style="width:20px; vertical-align:middle; margin-right:8px;"> Exchange Configuration </label> </div> <div class="form-row wide-label-amqp-in exchange-configuration-section"> <label for="node-input-exchangeType"><i class="fa fa-filter"></i>&nbsp;&nbsp;Type</label> <select id="node-input-exchangeType"> <option value="topic">Topic</option> <option value="direct">Direct</option> <option value="fanout">Fanout</option> <option value="headers">Headers</option> </select> </div> <div class="form-row wide-label-amqp-in exchange-configuration-section"> <label for="node-input-exchangeName" style="width: 30%"><i class="fa fa-tag"></i>&nbsp;&nbsp;Exchange Name</label> <input type="text" id="node-input-exchangeName" placeholder="Leave blank for the default exchange"> </div> <div class="form-row wide-label-amqp-in routing-key-form-input exchange-configuration-section"> <label for="node-input-exchangeRoutingKey"><i class="fa fa-filter"></i>&nbsp;&nbsp;Routing Key</label> <input type="text" id="node-input-exchangeRoutingKey"> </div> <div class="form-tips routing-key-form-input exchange-configuration-section"> <i class="fa fa-info-circle"></i> You can specify multiple routing keys separated by commas </div> <div class="form-row wide-label-amqp-in headers-form-input exchange-configuration-section"> <label for="node-input-headers"><i class="fa fa-filter"></i>&nbsp;&nbsp;Headers</label> <input type="text" id="node-input-headers"> </div> <br class="exchange-configuration-section"> <div class="form-row exchange-configuration-section"> <label>&nbsp;</label> <input style="width:20px; vertical-align:baseline; margin-right:5px;" type="checkbox" id="node-input-exchangeDurable"> <label style="width:auto; margin-top:7px;" for="node-input-exchangeDurable">Durable</label> </div> <div class="form-row exchange-configuration-section"> <label>&nbsp;</label> <input style="width:20px; vertical-align:baseline; margin-right:5px;" type="checkbox" id="node-input-autoCreateExchangeBindings"> <label style="width:auto; margin-top:7px;" for="node-input-autoCreateExchangeBindings">Auto-create</label> </div> <hr> <h4>Queue Configuration</h4> <div class="form-row wide-label-amqp-in"> <label for="node-input-queueName"><i class="fa fa-tag"></i>&nbsp;&nbsp;Queue Name</label> <input type="text" id="node-input-queueName" placeholder="Leave blank to auto-generate"> </div> <div class="form-row wide-label-amqp-in-manual-ack"> <label for="node-input-queueName"><i class="fa fa-tag"></i>&nbsp;&nbsp;Queue Type</label> <input type="text" id="node-input-queueType"> </div> <div class="form-row"> <label>&nbsp;</label> <input style="width:20px; vertical-align:baseline; margin-right:5px;" type="checkbox" id="node-input-queueExclusive"> <label style="width:auto; margin-top:7px;" for="node-input-queueExclusive">Exclusive</label> </div> <div class="form-row"> <label>&nbsp;</label> <input style="width:20px; vertical-align:baseline; margin-right:5px;" type="checkbox" id="node-input-queueDurable"> <label style="width:auto; margin-top:7px;" for="node-input-queueDurable">Durable</label> </div> <div class="form-row"> <label>&nbsp;</label> <input style="width:20px; vertical-align:baseline; margin-right:5px;" type="checkbox" id="node-input-queueAutoDelete"> <label style="width:auto; margin-top:7px;" for="node-input-queueAutoDelete">Auto Delete</label> </div> <div class="form-row"> <label>&nbsp;</label> <input style="width:20px; vertical-align:baseline; margin-right:5px;" type="checkbox" id="node-input-autoCreateQueue"> <label style="width:auto; margin-top:7px;" for="node-input-autoCreateQueue">Auto-create</label> </div> <div class="form-row wide-label-amqp-in"> <label for="node-input-queueArguments"><i class="fa fa-tag"></i>&nbsp;&nbsp;Queue Arguments</label> <input type="text" id="node-input-queueArguments"> </div> </script> <script type="text/html" data-help-name="amqp-in"> <p>Connects to an AMQP broker and receives messages.</p> <h3>Outputs</h3> <dl class="message-properties"> <dt>fields <span class="property-type">object</span> </dt> <dd> An <a href="http://www.squaremobius.net/amqp.node/" target="_blank">amqplib</a> fields object. Contains: <ul> <li><code>consumerTag</code>: string</code></li> <li><code>deliveryTag</code>: number</code></li> <li><code>redelivered</code>: boolean</code></li> <li><code>exchange</code>: string</code></li> <li><code>routingKey</code>: string</code></li> </ul> </dd> <dt>properties <span class="property-type">object</span> </dt> <dd> Standard AMQP message properties as specified in <a href="https://www.squaremobius.net/amqp.node/channel_api.html#channel_publish" target="_blank">the amqplib docs</a>. <br /> <ul> <li><code>contentType</code>: any | undefined</li> <li><code>contentEncoding</code>: any | undefined</li> <li><code>headers</code>: Object | undefined</li> <li><code>deliveryMode</code>: any | undefined</li> <li><code>priority</code>: any | undefined</li> <li><code>correlationId</code>: any | undefined</li> <li><code>replyTo</code>: any | undefined</li> <li><code>expiration</code>: any | undefined</li> <li><code>messageId</code>: any | undefined</li> <li><code>timestamp</code>: any | undefined</li> <li><code>type</code>: any | undefined</li> <li><code>userId</code>: any | undefined</li> <li><code>appId</code>: any | undefined</li> <li><code>clusterId</code>: any | undefined</li> </ul> </dd> <dt>content <span class="property-type">buffer</span> </dt> <dt>payload <span class="property-type">json | object | primitive</span> </dt> <dd>the payload of the message received. </dd> </dl> <h3>Inputs</h3> <dl class="message-properties"> <dt>payload.reconnectCall <span class="property-type">boolean</span> </dt> <dd>Set to <code>true</code> to trigger a reconnect.</dd> </dl> <h3>Behavior Notes</h3> <ul> <li>When <code>noAck</code> is <code>false</code>, the node acknowledges messages immediately after receipt and before downstream processing.</li> <li>Incoming payload is parsed as JSON when possible; if parsing fails, the raw value is passed through.</li> </ul> <h3>References</h3> <ul> <li>This node relies on the <a href="http://www.squaremobius.net/amqp.node/" target="_blank">amqplib</a> library.</li> <li>Project repository: <a href="https://github.com/frankvdb7/node-red-contrib-amqp" target="_blank">https://github.com/frankvdb7/node-red-contrib-amqp</a></li> </ul> </script>