Update stomp docs, fix json parse over-optimism.

This commit is contained in:
dceejay 2015-04-17 09:29:58 +01:00
parent 88ae31a6b8
commit 31318b03d7
4 changed files with 31 additions and 5 deletions

View File

@ -31,6 +31,14 @@
<script type="text/x-red" data-help-name="stomp in">
<p>Connects to a server using the Stomp protocol to receive messages.</p>
<p>If the message received is JSON <b>msg.payload</b> will be parsed into an
object. If not it will be the raw data.</p>
<p><b>msg.headers</b> contains any header information that was also delivered.</p>
<p><b>msg.topic</b> is set to the predefined subscription topic.</p>
<p><b>Note</b>: While not a requirement of the Stomp protocol, if connecting to an ActiveMQ server, the destination should
begin with <i>"/queue/"</i> or with <i>"/topic/"</i>. See
<a href="https://stomp.github.io/stomp-specification-1.0.html#frame-SEND" target="new">Stomp 1.0 spec</a>
for more details.</p>
</script>
<script type="text/javascript">
@ -72,7 +80,12 @@
<script type="text/x-red" data-help-name="stomp out">
<p>Connects to an Stomp capable server to send messages.</p>
<p>The <b>Destination</b> field is optional. If set it overrides the <b>msg.topic</b> property of the message.</p>
<p>The <b>Destination</b> field is optional. If set it overrides the <b>msg.topic</b>
property of the message.</p>
<p><b>Note</b>: While not a requirement of the Stomp protocol, if connecting to an ActiveMQ server, the destination should
begin with <i>"/queue/"</i> or with <i>"/topic/"</i>. See
<a href="https://stomp.github.io/stomp-specification-1.0.html#frame-SEND" target="new">Stomp 1.0 spec</a>
for more details.</p>
</script>
<script type="text/javascript">

View File

@ -57,7 +57,14 @@ module.exports = function(RED) {
node.status({fill:"green",shape:"dot",text:"connected"});
node.log('subscribed to: '+node.topic);
node.client.subscribe(node.topic, function(body, headers) {
msg.payload = JSON.parse(body);
try {
msg.payload = JSON.parse(body);
}
catch(e) {
msg.payload = body;
}
msg.headers = headers;
msg.topic = node.topic;
node.send(msg);
});
}, function(error) {

View File

@ -16,6 +16,12 @@ Usage
Connects to a Stomp capable server to send and receive messages.
The **destination** field is optional. If set it overrides the **msg.topic** property of the message.
The **destination** field is optional. If set it overrides the **msg.topic**
property of the message.
As noted [here](https://github.com/easternbloc/node-stomp-client#queue-names),
while not a requirement of the Stomp protocol,
if talking to an **ActiveMQ** server the *destination* should begin with
**"/queue/"** or with **"/topic/"**.
This node only uses the simple security version of the stomp-client.

View File

@ -1,9 +1,9 @@
{
"name" : "node-red-node-stomp",
"version" : "0.0.2",
"version" : "0.0.3",
"description" : "A Node-RED node to publish and subscribe to/from a Stomp server",
"dependencies" : {
"stomp-client" : "0.5.0"
"stomp-client" : "0.6.2"
},
"repository" : {
"type":"git",