atomic-jetstream
Version:
NATS JetStream module for Brobridge Atomic
289 lines (269 loc) • 8.69 kB
HTML
<script type="text/javascript">
RED.nodes.registerType('NATS JetStream Consumer', {
category: 'function',
color: '#00bb88',
credentials: {
},
defaults: {
name: {
value: ''
},
server: {
value: '',
type: 'NATS JetStream Server'
},
subjects: {
value: '',
required: true,
},
delivery: {
value: 'last',
required: true
},
stream: {
value: 'none',
required: true
},
ensurestream: {
value: '',
type: 'NATS JetStream Stream',
required: false
},
consumertype: {
value: 'ephemeral',
required: true
},
durable: {
value: '',
},
startseq: {
value: 0,
},
starttime: {
value: 0,
},
ack: {
value: 'auto',
required: true
},
maxackpending: {
value: 2000,
required: true
},
ackwait: {
value: 10000,
},
maxworkerpending: {
value: 1000,
},
maxdeliver: {
value: -1,
},
payloadType: {
value: "json",
required: true
},
},
inputs: 0,
outputs: 1,
icon: 'nats-icon-white.png',
label: function() {
return this.name || 'NATS JetStream Consumer';
},
oneditprepare: function() {
let node = this;
// Stream
function updateStreamOptions() {
switch($('#node-input-stream').val()) {
case 'ensure':
$('#node-row-ensurestream').show();
break;
default:
$('#node-row-ensurestream').hide();
}
}
updateStreamOptions();
$("#node-input-stream").on("change", function() {
updateStreamOptions();
});
// Consumer type
function updateConsumerType() {
switch($('#node-input-consumertype').val()) {
case 'ephemeral':
$('#node-row-durable').hide();
$('#node-row-maxworkerpending').hide();
$('#node-input-ack').prop('disabled', false)
break;
case 'queueGroup':
// only manual ack can be selected
$('#node-input-ack')
.prop('disabled', 'disabled')
.val('manual')
.change();
$('#node-row-durable').show();
$('#node-row-maxworkerpending').show();
break;
default:
$('#node-input-ack').prop('disabled', false)
$('#node-row-durable').show();
$('#node-row-maxworkerpending').hide();
}
}
updateConsumerType();
$("#node-input-consumertype").on("change", function() {
updateConsumerType();
});
// Delivery
function updateDeliveryOptions() {
switch($('#node-input-delivery').val()) {
case 'startSeq':
$('#node-row-startseq').show();
$('#node-row-starttime').hide();
break;
case 'startTime':
$('#node-row-startseq').hide();
$('#node-row-starttime').show();
break;
default:
$('#node-row-startseq').hide();
$('#node-row-starttime').hide();
}
}
updateDeliveryOptions();
$("#node-input-delivery").on("change", function() {
updateDeliveryOptions();
});
// Initialize inputs
$('#node-input-startseq').typedInput({
type: "num"
});
$('#node-input-starttime').typedInput({
type: "num"
});
// Acknowledge
function updateAckOptions() {
switch($('#node-input-ack').val()) {
case 'manual':
$('#node-row-ackmanual').show();
break;
default:
$('#node-row-ackmanual').hide();
}
}
updateAckOptions();
$("#node-input-ack").on("change", function() {
updateAckOptions();
});
// Initialize inputs
$('#node-input-ackwait').typedInput({
type: "num"
});
}
});
</script>
<script type="text/x-red" data-template-name="NATS JetStream Consumer">
<div class="form-row">
<label for="node-input-name" style="width: 130px"><i class="fa fa-stack-exchange"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-server" style="width: 130px"><i class="fa fa-server"></i> Server</label>
<input type="text" id="node-input-server" placeholder="localhost:4222">
</div>
<div class="form-row">
<label for="node-input-stream" style="width: 130px"><i class="fa fa-archive"></i> Stream Options</label>
<select id="node-input-stream" style='width:70%'>
<option value="none">No specified stream</option>
<option value="ensure">Ensure stream exists</option>
</select>
<div id="node-row-ensurestream" style="margin-left: 30px; margin-top: 10px;" class="hide">
<div class="form-row">
<label for="node-input-ensurestream"><i class="fa fa-inbox"></i> Stream</label>
<input type="text" id="node-input-ensurestream" style="width: 70%;">
</div>
</div>
</div>
<div class="form-row">
<label for="node-input-subjects" style="width: 130px"><i class="fa fa-hashtag"></i> Subjects</label>
<input type="text" id="node-input-subjects" placeholder="(empty)">
</div>
<div class="form-row">
<label for="node-input-consumertype" style="width: 130px"><i class="fa fa-sitemap"></i> Type</label>
<select id="node-input-consumertype" style='width:70%'>
<option value="ephemeral">Ephemeral</option>
<option value="durable">Durable</option>
<option value="queueGroup">Queue Group</option>
</select>
<div id="node-row-durable" style="margin-left: 30px; margin-top: 10px;" class="hide">
<div class="form-row">
<label for="node-input-durable">Durable</label>
<input type="text" id="node-input-durable">
</div>
</div>
<div id="node-row-maxworkerpending" style="margin-left: 30px; margin-top: 10px;" class="hide">
<div class="form-row">
<label for="node-input-maxworkerpending">Max Pending</label>
<input type="text" id="node-input-maxworkerpending" style="width:100px" placeholder="1000"> message(s) per worker
</div>
</div>
</div>
<div class="form-row">
<label for="node-input-delivery" style="width: 130px"><i class="fa fa-play"></i> Start At</label>
<select id="node-input-delivery" style='width:70%'>
<option value="last">Last</option>
<option value="new">New</option>
<option value="all">All</option>
<option value="startSeq">Start Sequence</option>
<option value="startTime">Start Time</option>
</select>
<div id="node-row-startseq" style="margin-left: 30px; margin-top: 10px;" class="hide">
<div class="form-row">
<label for="node-input-startseq"><i class="fa fa-map-marker"></i> Sequence</label>
<input type="text" id="node-input-startseq" style="width:100px" placeholder="0">
</div>
</div>
<div id="node-row-starttime" style="margin-left: 30px; margin-top: 10px;" class="hide">
<div class="form-row">
<label for="node-input-starttime"><i class="fa fa-history"></i> Timestamp</label>
<input type="text" id="node-input-starttime" style="width:100px" placeholder="0">
</div>
</div>
</div>
<div class="form-row">
<label for="node-input-ack" style="width: 130px"><i class="fa fa-check-circle"></i> Acknowledge</label>
<select id="node-input-ack" style='width:70%'>
<option value="auto">Auto</option>
<option value="manual">Manual</option>
</select>
<div id="node-row-ackmanual" style="margin-left: 30px; margin-top: 10px;" class="hide">
<div class="form-row">
<label for="node-input-ackwait"><i class="fa fa-history"></i> Wait time</label>
<input type="text" id="node-input-ackwait" style="width:100px" placeholder="0"> ms
</div>
<div class="form-row">
<label for="node-input-maxackpending"><i class="fa fa-stack-exchange"></i> Max Pending</label>
<input type="text" id="node-input-maxackpending" style="width:100px" placeholder="2000">
</div>
</div>
</div>
<div class="form-row">
<label for="node-input-client-opts" style="width: 100%"><i class="fa fa-sliders"></i> Advanced Options</label>
<div style="margin-left: 30px; margin-top: 10px;">
<div class="form-row">
<label for="node-input-maxdeliver"><i class="fa fa-comments"></i> Max Deliver</label>
<input type="text" id="node-input-maxdeliver" style="width:100px" placeholder="-1">
</div>
</div>
</div>
<div class="form-row">
<label for="node-input-payloadType" style="width: 130px"><i class="fa fa-stack-exchange"></i> Payload Type</label>
<select id="node-input-payloadType" style='width:70%'>
<option value="json">JSON</option>
<option value="string">String</option>
<option value="buffer">Buffer</option>
</select>
</div>
</script>
<script type="text/html" data-help-name="NATS JetStream Consumer">
<p>Consumer to consume stream data from NATS JetStream server</p>
</script>