consolidated/stompjs/src/compatibility/compat-client.ts
Available for backward compatibility, please shift to using Client.
Deprecated
Part of @stomp/stompjs
.
To upgrade, please follow the Upgrade Guide
Public maxWebSocketFrameSize |
Type : number
|
Default value : 16 * 1024
|
It is no op now. No longer needed. Large packets work out of the box. |
Public appendMissingNULLonIncoming |
Type : boolean
|
Default value : false
|
Inherited from
Client
|
Defined in
Client:269
|
Workaround for a React Native WebSocket bug, where messages containing Enabling this appends a Warning:
Example:
|
Public beforeConnect |
Type : function
|
Inherited from
Client
|
Defined in
Client:460
|
Callback executed before initiating a connection to the STOMP broker. This callback allows users to modify connection options dynamically, such as updating credentials or connection parameters, before the connection is made. As of version 5.1, this callback supports Example:
|
Public brokerURL |
Type : string | undefined
|
Inherited from
Client
|
Defined in
Client:56
|
The URL for the STOMP broker to connect to.
Example: Use this property to define the broker's WebSocket endpoint. Note:
|
Public connectHeaders |
Type : StompHeaders
|
Inherited from
Client
|
Defined in
Client:312
|
Connection headers to be sent during the connection handshake. Keys like Example:
|
Public connectionTimeout |
Type : number
|
Default value : 0
|
Inherited from
Client
|
Defined in
Client:107
|
Timeout for establishing STOMP connection, in milliseconds. If the connection is not established within this period, the attempt will fail.
The default is Example:
|
Public debug |
Type : debugFnType
|
Inherited from
Client
|
Defined in
Client:574
|
Set a custom debug function to capture debug messages. By default, debug messages are discarded. To log messages to the console, you can use:
Note: This method does not support configurable log levels, and the output can be verbose. Be cautious as debug messages may contain sensitive information, such as credentials or tokens. |
Public discardWebsocketOnCommFailure |
Type : boolean
|
Default value : false
|
Inherited from
Client
|
Defined in
Client:591
|
Instruct the library to immediately terminate the socket on communication failures, even before the WebSocket is completely closed. This is particularly useful in browser environments where WebSocket closure may get delayed, causing prolonged reconnection intervals under certain failure conditions. Example:
Default value: |
Public forceBinaryWSFrames |
Type : boolean
|
Default value : false
|
Inherited from
Client
|
Defined in
Client:254
|
Forces all WebSocket frames to use binary transport, irrespective of payload type. Default behavior determines frame type based on payload (e.g., binary data for ArrayBuffers). Example:
|
Public heartbeatIncoming |
Type : number
|
Default value : 10000
|
Inherited from
Client
|
Defined in
Client:171
|
Interval (in milliseconds) for receiving heartbeat signals from the server. Specifies the expected frequency of heartbeats sent by the server. Set to Example:
|
Public heartbeatOutgoing |
Type : number
|
Default value : 10000
|
Inherited from
Client
|
Defined in
Client:199
|
Interval (in milliseconds) for sending heartbeat signals to the server. Specifies how frequently heartbeats should be sent to the server. Set to Example:
|
Public heartbeatStrategy |
Type : TickerStrategy
|
Default value : TickerStrategy.Interval
|
Inherited from
Client
|
Defined in
Client:217
|
Strategy for sending outgoing heartbeats. Options:
Note:
Example:
|
Public heartbeatToleranceMultiplier |
Type : number
|
Default value : 2
|
Inherited from
Client
|
Defined in
Client:187
|
Multiplier for adjusting tolerance when processing heartbeat signals. Tolerance level is calculated using the multiplier:
Default value is Example:
|
Public logRawCommunication |
Type : boolean
|
Inherited from
Client
|
Defined in
Client:558
|
Enable or disable logging of the raw communication with the broker. When enabled, it logs the raw frames exchanged with the broker. If disabled, only the headers of the parsed frames will be logged. Caution: Raw communication frames must contain valid UTF-8 strings, as any non-compliant data can cause errors in the logging process. Changes to this setting will take effect during the next broker reconnect. Example:
|
Public maxReconnectDelay |
Type : number
|
Default value : 15 * 60 * 1000
|
Inherited from
Client
|
Defined in
Client:143
|
Maximum delay (in milliseconds) between reconnection attempts when using exponential backoff. Default is 15 minutes ( Example:
|
Public maxWebSocketChunkSize |
Type : number
|
Default value : 8 * 1024
|
Inherited from
Client
|
Defined in
Client:242
|
Maximum size (in bytes) for individual WebSocket chunks if splitLargeFrames is enabled. Default is 8 KB ( |
Public onChangeState |
Type : function
|
Inherited from
Client
|
Defined in
Client:646
|
Callback invoked whenever the client's state changes. This callback can be used to monitor transitions between various states, such as Example:
|
Public onConnect |
Type : frameCallbackType
|
Inherited from
Client
|
Defined in
Client:476
|
Callback executed upon every successful connection to the STOMP broker. This callback is invoked after the connection is established and the CONNECTED frame is received from the broker. It provides access to the broker's response frame, allowing users to parse its headers or other data. Example:
|
Public onDisconnect |
Type : frameCallbackType
|
Inherited from
Client
|
Defined in
Client:493
|
Callback executed upon successful disconnection from the STOMP broker. The callback is invoked when the DISCONNECT receipt is received from the broker. Note that due to the design of the STOMP protocol or communication interrupts, the DISCONNECT receipt may not always be received. For handling such cases, use Client#onWebSocketClose. Example:
|
Public onHeartbeatLost |
Type : emptyCallbackType
|
Inherited from
Client
|
Defined in
Client:423
|
Callback invoked when no heartbeat is received from the broker within the acceptable interval, indicating a potential communication issue or connection failure. This callback is triggered when the heartbeat interval defined by Note: The library handles this condition internally and takes appropriate actions, such as marking the connection as failed. This callback is available for implementing custom recovery strategies or additional notifications. Usage:
|
Public onHeartbeatReceived |
Type : emptyCallbackType
|
Inherited from
Client
|
Defined in
Client:403
|
Callback invoked when a heartbeat message is received from the STOMP broker. Heartbeats ensure that the connection remains active and responsive. This callback is executed on every received heartbeat. It is useful for monitoring connection health or logging heartbeat activity. Note: The library handles heartbeats internally to maintain and verify connection status. Implementing this callback is optional and primarily for custom monitoring or debugging. Usage:
|
Public onStompError |
Type : frameCallbackType
|
Inherited from
Client
|
Defined in
Client:509
|
Callback executed when an ERROR frame is received from the STOMP broker. Receiving an ERROR frame typically indicates a problem with the subscription, message format, or protocol violation. The broker will usually close the connection after sending an ERROR frame. Example:
|
Public onUnhandledFrame | ||||
Type : frameCallbackType
|
||||
Inherited from
Client
|
||||
Defined in
Client:384
|
||||
Callback invoked when a frame of an unknown or unexpected type is received from the broker. This is intended as a fallback for handling unexpected or unsupported frames sent by the broker. Usage:
|
||||
Parameters :
|
Public onUnhandledMessage | ||||
Type : messageCallbackType
|
||||
Inherited from
Client
|
||||
Defined in
Client:354
|
||||
Callback invoked for any unhandled messages received from the broker. This is particularly useful for handling messages sent to RabbitMQ temporary queues or other queues where no explicit subscription exists. It can also be triggered by stray messages received while a subscription is being unsubscribed. Usage:
|
||||
Parameters :
|
Public onUnhandledReceipt | ||||
Type : frameCallbackType
|
||||
Inherited from
Client
|
||||
Defined in
Client:366
|
||||
Callback invoked when the broker sends a receipt indicating the completion of an operation. Receipts are typically requested using the Client#watchForReceipt function. Usage Example: See Client#watchForReceipt. |
||||
Parameters :
|
Public onWebSocketClose |
Type : closeEventCallbackType
|
Inherited from
Client
|
Defined in
Client:525
|
Callback executed when the underlying WebSocket is closed. This can occur due to various reasons, such as network interruptions or broker shutdown. The callback provides the WebSocket CloseEvent, which contains details about the closure. Example:
|
Public onWebSocketError |
Type : wsErrorCallbackType
|
Inherited from
Client
|
Defined in
Client:540
|
Callback executed when the underlying WebSocket raises an error. This callback provides an Event representing the error raised by the WebSocket. Example:
|
Public reconnectDelay |
Type : number
|
Default value : 5000
|
Inherited from
Client
|
Defined in
Client:124
|
Delay (in milliseconds) between reconnection attempts if the connection drops. Set to Example:
|
Public reconnectTimeMode |
Type : ReconnectionTimeMode
|
Default value : ReconnectionTimeMode.LINEAR
|
Inherited from
Client
|
Defined in
Client:159
|
Mode for determining the time interval between reconnection attempts. Available modes:
Example:
|
Public splitLargeFrames |
Type : boolean
|
Default value : false
|
Inherited from
Client
|
Defined in
Client:235
|
Enables splitting of large text WebSocket frames into smaller chunks. This setting is enabled for brokers that support only chunked messages (e.g., Java Spring-based brokers).
Default is Warning:
Example:
|
Public state |
Type : ActivationState
|
Default value : ActivationState.INACTIVE
|
Inherited from
Client
|
Defined in
Client:664
|
Current activation state of the client. Possible states:
Note: The client may transition directly from |
Public stompVersions |
Default value : Versions.default
|
Inherited from
Client
|
Defined in
Client:68
|
STOMP protocol versions to use during the handshake. By default, the client will attempt
versions Example:
|
Public webSocketFactory |
Type : | undefined
|
Inherited from
Client
|
Defined in
Client:94
|
A function that returns a WebSocket or a similar object (e.g., SockJS) to establish connections. This is an alternative to Client#brokerURL. Using this allows finer control over WebSocket creation, especially for custom wrappers or when working in non-standard environments. Example:
Note:
|
Public connect | ||||||
connect(...args: any[])
|
||||||
Available for backward compatibility, please shift to using Client#activate. Deprecated The overloads:
params:
To upgrade, please follow the Upgrade Guide
Parameters :
Returns :
void
|
Public disconnect | ||||||||||||
disconnect(disconnectCallback?: any, headers: StompHeaders)
|
||||||||||||
Available for backward compatibility, please shift to using Client#deactivate. Deprecated See: Client#onDisconnect, and Client#disconnectHeaders To upgrade, please follow the Upgrade Guide
Parameters :
Returns :
void
|
Public send | ||||||||||||||||
send(destination: string, headers: literal type, body: string)
|
||||||||||||||||
Available for backward compatibility, use Client#publish. Send a message to a named destination. Refer to your STOMP broker documentation for types and naming of destinations. The headers will, typically, be available to the subscriber. However, there may be special purpose headers corresponding to your STOMP broker. Deprecated, use Client#publish Note: Body must be String. You will need to covert the payload to string in case it is not string (e.g. JSON)
To upgrade, please follow the Upgrade Guide
Parameters :
Returns :
void
|
Public abort | ||||||||
abort(transactionId: string)
|
||||||||
Inherited from
Client
|
||||||||
Defined in
Client:1253
|
||||||||
Aborts a transaction. It is strongly recommended to call abort directly on the transaction object returned by client#begin. Example:
Parameters :
Returns :
void
|
Public ack | ||||||||||||||||||||
ack(messageId: string, subscriptionId: string, headers: StompHeaders)
|
||||||||||||||||||||
Inherited from
Client
|
||||||||||||||||||||
Defined in
Client:1278
|
||||||||||||||||||||
Acknowledges receipt of a message. Typically, this should be done by calling ack directly on the IMessage instance passed to the subscription callback. Example:
Parameters :
Returns :
void
|
Public activate |
activate()
|
Inherited from
Client
|
Defined in
Client:761
|
Activates the client, initiating a connection to the STOMP broker. On activation, the client attempts to connect and sets its state to To stop reconnection attempts and disconnect, call Client#deactivate. Example:
If the client is currently
Returns :
void
|
Public begin | ||||||||
begin(transactionId?: string)
|
||||||||
Inherited from
Client
|
||||||||
Defined in
Client:1211
|
||||||||
Starts a new transaction. The returned ITransaction object provides methods for commit and abort. If Example:
Parameters :
Returns :
ITransaction
An instance of {@link ITransaction}. |
Public commit | ||||||||
commit(transactionId: string)
|
||||||||
Inherited from
Client
|
||||||||
Defined in
Client:1232
|
||||||||
Commits a transaction. It is strongly recommended to call commit on the transaction object returned by client#begin. Example:
Parameters :
Returns :
void
|
Public configure | ||||||||
configure(conf: StompConfig)
|
||||||||
Inherited from
Client
|
||||||||
Defined in
Client:729
|
||||||||
Updates the client's configuration. All properties in the provided configuration object will override the current settings. Additionally, a warning is logged if Example:
Parameters :
Returns :
void
|
Public Async deactivate | ||||||||||
deactivate(options: literal type)
|
||||||||||
Inherited from
Client
|
||||||||||
Defined in
Client:976
|
||||||||||
Disconnects the client and stops the automatic reconnection loop. If there is an active STOMP connection at the time of invocation, the appropriate callbacks
will be triggered during the shutdown sequence. Once deactivated, the client will enter the
Behavior:
Experimental Option:
Example:
Parameters :
Returns :
Promise<void>
A Promise that resolves when the deactivation process completes. |
Public forceDisconnect |
forceDisconnect()
|
Inherited from
Client
|
Defined in
Client:1040
|
Forces a disconnect by directly closing the WebSocket. Unlike a normal disconnect, this does not send a DISCONNECT sequence to the broker but
instead closes the WebSocket connection directly. After forcing a disconnect, the client
will automatically attempt to reconnect based on its Note: To prevent further reconnect attempts, call Client#deactivate. Example:
Returns :
void
|
Public nack | ||||||||||||||||||||
nack(messageId: string, subscriptionId: string, headers: StompHeaders)
|
||||||||||||||||||||
Inherited from
Client
|
||||||||||||||||||||
Defined in
Client:1309
|
||||||||||||||||||||
Rejects a message (negative acknowledgment). Like acknowledgments, this should typically be done by calling nack directly on the IMessage instance passed to the subscription callback. Example:
Parameters :
Returns :
void
|
Public publish | ||||||
publish(params: IPublishParams)
|
||||||
Inherited from
Client
|
||||||
Defined in
Client:1088
|
||||||
Sends a message to the specified destination on the STOMP broker. The Content-Length Behavior:
Notes:
Example:
Parameters :
Returns :
void
|
Public subscribe | ||||||||||||||||||||
subscribe(destination: string, callback: messageCallbackType, headers: StompHeaders)
|
||||||||||||||||||||
Inherited from
Client
|
||||||||||||||||||||
Defined in
Client:1158
|
||||||||||||||||||||
Subscribes to a destination on the STOMP broker. The callback is triggered for each message received from the subscribed destination. The message is passed as an IMessage instance. Subscription ID:
Example:
Parameters :
Returns :
StompSubscription
A {@link StompSubscription} which can be used to manage the subscription. |
Public unsubscribe | |||||||||||||||
unsubscribe(id: string, headers: StompHeaders)
|
|||||||||||||||
Inherited from
Client
|
|||||||||||||||
Defined in
Client:1188
|
|||||||||||||||
Unsubscribes from a subscription on the STOMP broker. Prefer using the
This method can also be used directly with the subscription ID. Example:
Parameters :
Returns :
void
|
Public watchForReceipt | ||||||||||||
watchForReceipt(receiptId: string, callback: frameCallbackType)
|
||||||||||||
Inherited from
Client
|
||||||||||||
Defined in
Client:1123
|
||||||||||||
Monitors for a receipt acknowledgment from the broker for specific operations. Add a The callback is invoked with the corresponding IFrame when the receipt is received. Example:
Parameters :
Returns :
void
|
reconnect_delay | ||||||
setreconnect_delay(value: number)
|
||||||
Available for backward compatibility, renamed to Client#reconnectDelay. Deprecated
Parameters :
Returns :
void
|
ws |
getws()
|
Available for backward compatibility, renamed to Client#webSocket. Deprecated
Returns :
any
|
version |
getversion()
|
Available for backward compatibility, renamed to Client#connectedVersion. Deprecated |
onreceive | ||||||
getonreceive()
|
||||||
Available for backward compatibility, renamed to Client#onUnhandledMessage. Deprecated
Returns :
messageCallbackType
|
||||||
setonreceive(value: messageCallbackType)
|
||||||
Available for backward compatibility, renamed to Client#onUnhandledMessage. Deprecated
Parameters :
Returns :
void
|
onreceipt | ||||||
getonreceipt()
|
||||||
Available for backward compatibility, renamed to Client#onUnhandledReceipt. Prefer using Client#watchForReceipt. Deprecated
Returns :
frameCallbackType
|
||||||
setonreceipt(value: frameCallbackType)
|
||||||
Available for backward compatibility, renamed to Client#onUnhandledReceipt. Deprecated
Parameters :
Returns :
void
|
heartbeat | ||||||
getheartbeat()
|
||||||
Available for backward compatibility, renamed to Client#heartbeatIncoming Client#heartbeatOutgoing. Deprecated |
||||||
setheartbeat(value: literal type)
|
||||||
Available for backward compatibility, renamed to Client#heartbeatIncoming Client#heartbeatOutgoing. Deprecated
Parameters :
Returns :
void
|
import { Client } from '../client.js';
import { StompHeaders } from '../stomp-headers.js';
import { frameCallbackType, messageCallbackType } from '../types.js';
import { HeartbeatInfo } from './heartbeat-info.js';
/**
* Available for backward compatibility, please shift to using {@link Client}.
*
* **Deprecated**
*
* Part of `@stomp/stompjs`.
*
* To upgrade, please follow the [Upgrade Guide](https://stomp-js.github.io/guide/stompjs/upgrading-stompjs.html)
*/
export class CompatClient extends Client {
/**
* It is no op now. No longer needed. Large packets work out of the box.
*/
public maxWebSocketFrameSize: number = 16 * 1024;
/**
* Available for backward compatibility, please shift to using {@link Client}
* and [Client#webSocketFactory]{@link Client#webSocketFactory}.
*
* **Deprecated**
*
* @internal
*/
constructor(webSocketFactory: () => any) {
super();
this.reconnect_delay = 0;
this.webSocketFactory = webSocketFactory;
// Default from previous version
this.debug = (...message: any[]) => {
console.log(...message);
};
}
private _parseConnect(...args: any[]): any {
let closeEventCallback;
let connectCallback;
let errorCallback;
let headers: StompHeaders = {};
if (args.length < 2) {
throw new Error('Connect requires at least 2 arguments');
}
if (typeof args[1] === 'function') {
[headers, connectCallback, errorCallback, closeEventCallback] = args;
} else {
switch (args.length) {
case 6:
[
headers.login,
headers.passcode,
connectCallback,
errorCallback,
closeEventCallback,
headers.host,
] = args;
break;
default:
[
headers.login,
headers.passcode,
connectCallback,
errorCallback,
closeEventCallback,
] = args;
}
}
return [headers, connectCallback, errorCallback, closeEventCallback];
}
/**
* Available for backward compatibility, please shift to using [Client#activate]{@link Client#activate}.
*
* **Deprecated**
*
* The `connect` method accepts different number of arguments and types. See the Overloads list. Use the
* version with headers to pass your broker specific options.
*
* overloads:
* - connect(headers, connectCallback)
* - connect(headers, connectCallback, errorCallback)
* - connect(login, passcode, connectCallback)
* - connect(login, passcode, connectCallback, errorCallback)
* - connect(login, passcode, connectCallback, errorCallback, closeEventCallback)
* - connect(login, passcode, connectCallback, errorCallback, closeEventCallback, host)
*
* params:
* - headers, see [Client#connectHeaders]{@link Client#connectHeaders}
* - connectCallback, see [Client#onConnect]{@link Client#onConnect}
* - errorCallback, see [Client#onStompError]{@link Client#onStompError}
* - closeEventCallback, see [Client#onWebSocketClose]{@link Client#onWebSocketClose}
* - login [String], see [Client#connectHeaders](../classes/Client.html#connectHeaders)
* - passcode [String], [Client#connectHeaders](../classes/Client.html#connectHeaders)
* - host [String], see [Client#connectHeaders](../classes/Client.html#connectHeaders)
*
* To upgrade, please follow the [Upgrade Guide](../additional-documentation/upgrading.html)
*/
public connect(...args: any[]): void {
const out = this._parseConnect(...args);
if (out[0]) {
this.connectHeaders = out[0];
}
if (out[1]) {
this.onConnect = out[1];
}
if (out[2]) {
this.onStompError = out[2];
}
if (out[3]) {
this.onWebSocketClose = out[3];
}
super.activate();
}
/**
* Available for backward compatibility, please shift to using [Client#deactivate]{@link Client#deactivate}.
*
* **Deprecated**
*
* See:
* [Client#onDisconnect]{@link Client#onDisconnect}, and
* [Client#disconnectHeaders]{@link Client#disconnectHeaders}
*
* To upgrade, please follow the [Upgrade Guide](../additional-documentation/upgrading.html)
*/
public disconnect(
disconnectCallback?: any,
headers: StompHeaders = {},
): void {
if (disconnectCallback) {
this.onDisconnect = disconnectCallback;
}
this.disconnectHeaders = headers;
super.deactivate();
}
/**
* Available for backward compatibility, use [Client#publish]{@link Client#publish}.
*
* Send a message to a named destination. Refer to your STOMP broker documentation for types
* and naming of destinations. The headers will, typically, be available to the subscriber.
* However, there may be special purpose headers corresponding to your STOMP broker.
*
* **Deprecated**, use [Client#publish]{@link Client#publish}
*
* Note: Body must be String. You will need to covert the payload to string in case it is not string (e.g. JSON)
*
* ```javascript
* client.send("/queue/test", {priority: 9}, "Hello, STOMP");
*
* // If you want to send a message with a body, you must also pass the headers argument.
* client.send("/queue/test", {}, "Hello, STOMP");
* ```
*
* To upgrade, please follow the [Upgrade Guide](../additional-documentation/upgrading.html)
*/
public send(
destination: string,
headers: { [key: string]: any } = {},
body: string = '',
): void {
headers = (Object as any).assign({}, headers);
const skipContentLengthHeader = headers['content-length'] === false;
if (skipContentLengthHeader) {
delete headers['content-length'];
}
this.publish({
destination,
headers: headers as StompHeaders,
body,
skipContentLengthHeader,
});
}
/**
* Available for backward compatibility, renamed to [Client#reconnectDelay]{@link Client#reconnectDelay}.
*
* **Deprecated**
*/
set reconnect_delay(value: number) {
this.reconnectDelay = value;
}
/**
* Available for backward compatibility, renamed to [Client#webSocket]{@link Client#webSocket}.
*
* **Deprecated**
*/
get ws(): any {
return this.webSocket;
}
/**
* Available for backward compatibility, renamed to [Client#connectedVersion]{@link Client#connectedVersion}.
*
* **Deprecated**
*/
get version() {
return this.connectedVersion;
}
/**
* Available for backward compatibility, renamed to [Client#onUnhandledMessage]{@link Client#onUnhandledMessage}.
*
* **Deprecated**
*/
get onreceive(): messageCallbackType {
return this.onUnhandledMessage;
}
/**
* Available for backward compatibility, renamed to [Client#onUnhandledMessage]{@link Client#onUnhandledMessage}.
*
* **Deprecated**
*/
set onreceive(value: messageCallbackType) {
this.onUnhandledMessage = value;
}
/**
* Available for backward compatibility, renamed to [Client#onUnhandledReceipt]{@link Client#onUnhandledReceipt}.
* Prefer using [Client#watchForReceipt]{@link Client#watchForReceipt}.
*
* **Deprecated**
*/
get onreceipt(): frameCallbackType {
return this.onUnhandledReceipt;
}
/**
* Available for backward compatibility, renamed to [Client#onUnhandledReceipt]{@link Client#onUnhandledReceipt}.
*
* **Deprecated**
*/
set onreceipt(value: frameCallbackType) {
this.onUnhandledReceipt = value;
}
private _heartbeatInfo: HeartbeatInfo = new HeartbeatInfo(this);
/**
* Available for backward compatibility, renamed to [Client#heartbeatIncoming]{@link Client#heartbeatIncoming}
* [Client#heartbeatOutgoing]{@link Client#heartbeatOutgoing}.
*
* **Deprecated**
*/
get heartbeat() {
return this._heartbeatInfo;
}
/**
* Available for backward compatibility, renamed to [Client#heartbeatIncoming]{@link Client#heartbeatIncoming}
* [Client#heartbeatOutgoing]{@link Client#heartbeatOutgoing}.
*
* **Deprecated**
*/
set heartbeat(value: { incoming: number; outgoing: number }) {
this.heartbeatIncoming = value.incoming;
this.heartbeatOutgoing = value.outgoing;
}
}