Class: stompit.Client


new stompit.Client(transport, [options])

The transport parameter expects a stream.Duplex object argument. The transport must be in a connecting or connected state.

The constructor is useful if you're using a custom transport such a transform stream. However, if you are using any of the standard transports then you should avoid using the constructor and instead use the much more convenient stompit.connect function to instantiate a stompit.Client object and establish a connection.

Options:

client.connect(headers, [callback])

Send a CONNECT frame to the server.

If a callback function argument is given then it will be called on connect event.

Note: you must not call this method if you used stompit.connect function.

client.disconnect([callback])

Disconnect from server. A DISCONNECT frame is sent with a receipt request. No further transmissions are permitted while the disconnect is pending. The server should reply with a disconnect receipt and end the connection once all messages sent from the client are acknowledged.

The callback function is called when the connection is closed or when an error occurs.

client.destroy([error])

Close the connection immediately without warning the server. A DISCONNECT frame is not sent.

If an error argument is given then an error event is emitted from the client.

client.send(headers, [options])

Send or publish a message. This method returns a stream.Writable object for you to write the message content. The frame headers are transmitted once the message content writing begins i.e. on the first call to the write method.

Important headers:

Options:

client.sendFrame(command, headers, [options])

Send a frame to the server. A stream.Writable object is returned for you to write the frame body.

For available options see client.send method.

client.subscribe(headers, onMessageCallback)

Create a new subscription. A SUBSCRIBE frame is sent with the headers set in the headers argument. The onMessageCallback function is called each time a new message is received. Every message must be read and acknowledged, even if you don't consume the message in your application (in this case you would send a negative acknowledgment). You must not ignore a message, doing so would block other communications with the client. If you are unable to read a message then you must terminate the connection using the client.destroy method.

Important headers:

The onMessageCallback function has the parameters error, message. The message object extends stream.Readable

message.ack()

Send acknowledgement to server. This method should be called after the end event is emitted from the message object. Even if the subscription is in auto mode, you must still call one of the acknowledgment methods.

message.nack()

Send negative acknowledgement to server. This method should be called after the end event is emitted.

Do not use the message.nack method before reading all the message content. If you cannot read the message content then the connection must be terminated using the client.destroy method.

client.begin([headers])

Creates a transaction. A BEGIN frame is sent to the server. A transaction object is returned from the method. The transaction object will append a transaction identification header to any related outgoing frames.

transaction.send(headers, [options])

Same behaviour as client.send method.

transaction.commit([options])

Commit the transaction. A COMMIT frame is sent to the server. Use the onReceipt option to get confirmation from the server that this transaction was successfully committed.

The server may terminate the connection with an error frame if it cannot commit the transaction. In this case, an error event would be emitted from the client object.

transaction.abort([options])

Abort the transaction. An ABORT frame is sent to the server.