IPWorks MQ 2020 Node.js Edition

Questions / Feedback?

Subscribe Method

Subscribes to a message destination on the server.

Syntax

stomp.subscribe(destination, requireAcks, [callback])

Callback

The 'callback' parameter specifies a function which will be called when the operation completes (or an error is encountered). If the 'callback' parameter is not specified, then the method will block and will not return until the operation completes (or an error is encountered).

The callback for this method is defined as:

function(err, data){ }

'err' is the error that occurred. If there was no error, then 'err' is 'null'.

'data' is the value returned by the method.

'err' has 2 properties which hold detailed information:

err.code
err.message

Remarks

This method is used to subscribe to the specified message Destination on the server. The Id of the subscription is returned.

Once subscribed, the Subscribed event will fire and an item will be added to the Subscription* properties. The MessageIn event will fire anytime a message is received for any subscription.

The STOMP specification does not place any restrictions on Destination names. Instead, each STOMP server is free to define its own requirements for, and/or interpretations of, a Destination name; for example, a server might prohibit certain characters, require a specific format, or interpret some patterns in a special manner. Be sure to consult the documentation for your STOMP server to determine how to build proper Destination names.

If the RequireAcks parameter is set to True, the server will expect the class to send it a message acknowledgment for each message it delivers as part of this subscription. (Refer to the MessageIn event for more information about sending message acknowledgments).

Basic Subscriptions Example

stomp1.OnMessageIn += (s, e) => {
  Console.WriteLine("Received message from destination '" + e.Destination + "':");
  Console.WriteLine(e.Data);
};

string subId = stomp1.Subscribe("test/a/b", false);
// Some time later...
stomp1.Unsubscribe(subId);

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks MQ 2020 Node.js Edition - Version 20.0 [Build 8155]