# Class: StompClientConnection

## vertx-stomp-js/stomp_client_connection~ StompClientConnection

#### new StompClientConnection()

  Source:
    - stomp_client_connection.js, line 30

### Methods

#### abort(id, headers, receiptHandler) → {StompClientConnection}

  Aborts a transaction.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `id` | string | the transaction id, must not be `null`
  `headers` | Array.<string> | additional headers to send to the server. The `transaction` header is replaced by the value passed in the @{code id} parameter
  `receiptHandler` | function | the handler invoked when the `RECEIPT` frame associated with the transaction cancellation has been processed by the server. The handler receives the sent frame (`ABORT`).

  Source:
    - stomp_client_connection.js, line 324

  ##### Returns:

  the current StompClientConnection
  Type
    StompClientConnection

#### ack(id, txId, receiptHandler) → {StompClientConnection}

  Sends an acknowledgement for the given frame. It means that the frame has been handled and processed by the client. The sent acknowledgement is part of the transaction identified by the given id.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `id` | string | the message id of the message to acknowledge
  `txId` | string | the transaction id
  `receiptHandler` | function | the handler invoked when the `RECEIPT` frame associated with the acknowledgment has been processed by the server. The handler receives the sent frame (`ACK`).

  Source:
    - stomp_client_connection.js, line 385

  ##### Returns:

  the current StompClientConnection
  Type
    StompClientConnection

#### beginTX(id, headers, receiptHandler) → {StompClientConnection}

  Begins a transaction.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `id` | string | the transaction id, must not be `null`
  `headers` | Array.<string> | additional headers to send to the server. The `transaction` header is replaced by the value passed in the @{code id} parameter
  `receiptHandler` | function | the handler invoked when the `RECEIPT` frame associated with the transaction begin has been processed by the server. The handler receives the sent frame (`BEGIN`).

  Source:
    - stomp_client_connection.js, line 264

  ##### Returns:

  the current StompClientConnection
  Type
    StompClientConnection

#### close()

  Closes the connection without sending the `DISCONNECT` frame.
  Source:
    - stomp_client_connection.js, line 69

#### closeHandler(handler) → {StompClientConnection}

  Sets a handler notified when the STOMP connection is closed.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `handler` | function | the handler

  Source:
    - stomp_client_connection.js, line 227

  ##### Returns:

  the current StompClientConnection
  Type
    StompClientConnection

#### commit(id, headers, receiptHandler) → {StompClientConnection}

  Commits a transaction.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `id` | string | the transaction id, must not be `null`
  `headers` | Array.<string> | additional headers to send to the server. The `transaction` header is replaced by the value passed in the @{code id} parameter
  `receiptHandler` | function | the handler invoked when the `RECEIPT` frame associated with the transaction commit has been processed by the server. The handler receives the sent frame (`COMMIT`).

  Source:
    - stomp_client_connection.js, line 294

  ##### Returns:

  the current StompClientConnection
  Type
    StompClientConnection

#### disconnect(frame, receiptHandler) → {StompClientConnection}

  Disconnects the client. Unlike the StompClientConnection#close method, this method send the `DISCONNECT` frame to the server. This method lets you customize the `DISCONNECT` frame.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `frame` | Object | the `DISCONNECT` frame.
  `receiptHandler` | function | the handler invoked when the `RECEIPT` frame associated with the disconnection has been processed by the server. The handler receives the sent frame (`DISCONNECT`).

  Source:
    - stomp_client_connection.js, line 354

  ##### Returns:

  the current StompClientConnection
  Type
    StompClientConnection

#### errorHandler(handler) → {StompClientConnection}

  Sets a handler notified when an `ERROR` frame is received by the client. The handler receives the `ERROR` frame and a reference on the StompClientConnection.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `handler` | function | the handler

  Source:
    - stomp_client_connection.js, line 210

  ##### Returns:

  the current StompClientConnection
  Type
    StompClientConnection

#### nack(id, txId, receiptHandler) → {StompClientConnection}

  Sends a non-acknowledgement for the given frame. It means that the frame has not been handled by the client. The sent non-acknowledgement is part of the transaction identified by the given id.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `id` | string | the message id of the message to acknowledge
  `txId` | string | the transaction id
  `receiptHandler` | function | the handler invoked when the `RECEIPT` frame associated with the non-acknowledgment has been processed by the server. The handler receives the sent frame (`NACK`).

  Source:
    - stomp_client_connection.js, line 416

  ##### Returns:

  the current StompClientConnection
  Type
    StompClientConnection

#### pingHandler(handler) → {StompClientConnection}

  Sets a handler that let customize the behavior when a ping needs to be sent to the server. Be aware that changing the default behavior may break the compliance with the STOMP specification.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `handler` | function | the handler

  Source:
    - stomp_client_connection.js, line 245

  ##### Returns:

  the current StompClientConnection
  Type
    StompClientConnection

#### send(destination, headers, body, receiptHandler) → {StompClientConnection}

  Sends a `SEND` frame to the server to the given destination.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `destination` | string | the destination, must not be `null`
  `headers` | Array.<string> | the header. The `destination` header is replaced by the value given to the `destination` parameter
  `body` | Buffer | the body, may be `null`
  `receiptHandler` | function | the handler invoked when the `RECEIPT` frame associated with the sent frame has been received. The handler receives the sent frame.

  Source:
    - stomp_client_connection.js, line 100

  ##### Returns:

  the current StompClientConnection
  Type
    StompClientConnection

#### server() → {string}

  Source:
    - stomp_client_connection.js, line 83

  ##### Returns:

  - the server name.
  - Type
      string

#### session() → {string}

  Source:
    - stomp_client_connection.js, line 42

  ##### Returns:

  - the session id.
  - Type
      string

#### subscribe(destination, headers, handler, receiptHandler) → {string}

  Subscribes to the given destination.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `destination` | string | the destination, must not be `null`
  `headers` | Array.<string> | the headers to configure the subscription. It may contain the `ack` header to configure the acknowledgment policy. If the given set of headers contains the `id` header, this value is used as subscription id.
  `handler` | function | the handler invoked when a message is received on the given destination. Must not be `null`.
  `receiptHandler` | function | the handler invoked when the `RECEIPT` frame associated with the subscription has been received. The handler receives the sent frame (`SUBSCRIBE`).

  Source:
    - stomp_client_connection.js, line 147

  ##### Returns:

  the subscription id, which can either be the destination or the id set in the headers.
  Type
    string

#### unsubscribe(destination, headers, receiptHandler) → {StompClientConnection}

  Un-subscribes from the given destination. This method computes the subscription id as follows. If the given headers contains the `id` header, the header value is used. Otherwise the destination is used.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `destination` | string | the destination
  `headers` | Array.<string> | the headers
  `receiptHandler` | function | the handler invoked when the `RECEIPT` frame associated with the un-subscription has been received. The handler receives the sent frame (`UNSUBSCRIBE`).

  Source:
    - stomp_client_connection.js, line 182

  ##### Returns:

  the current StompClientConnection
  Type
    StompClientConnection

#### version() → {string}

  Source:
    - stomp_client_connection.js, line 56

  ##### Returns:

  - the STOMP protocol version negotiated with the server.
  - Type
      string