= Vert.x-Stomp
:toc: left

STOMP is the Simple (or Streaming) Text Orientated Messaging Protocol. STOMP
provides an interoperable wire format so that STOMP clients can communicate with any STOMP message broker to
provide easy and widespread messaging interoperability among many languages, platforms and brokers. Get more details about STOMP on https://stomp.github.io/index.html.

Vertx-Stomp is an implementation of a STOMP server and client. You can use the STOMP server with other clients and
use the STOMP client with other servers. The server and the client supports the version 1.0, 1.1 and 1.2 of the
STOMP protocol (see https://stomp.github.io/stomp-specification-1.2.html). The STOMP server can also be used as a
bridge with the vert.x event bus, or directly with web sockets (using StompJS).

== Using vertx-stomp

To use the Vert.x Stomp server and client, add the following dependency to the _dependencies_ section of your build
descriptor:

* Maven (in your `pom.xml`):

[source,xml,subs="+attributes"]
----
<dependency>
 <groupId>io.vertx</groupId>
 <artifactId>vertx-stomp</artifactId>
 <version>3.8.1</version>
</dependency>
----

* Gradle (in your `build.gradle` file):

[source,groovy,subs="+attributes"]
----
compile 'io.vertx:vertx-stomp:3.8.1'
----

== STOMP server

=== Creating a STOMP server

The simplest way to create an STOMP server, using all default options is as follows:

[source,ruby]
----
require 'vertx-stomp/stomp_server_handler'
require 'vertx-stomp/stomp_server'
server = VertxStomp::StompServer.create(vertx).handler(VertxStomp::StompServerHandler.create(vertx)).listen()

----

This creates a STOMP server listening on `localhost:61613` that is compliant with the STOMP specification.

You can configure the port and host in the `link:../../yardoc/VertxStomp/StompServer.html#listen-instance_method[listen]`
method:

[source,ruby]
----
require 'vertx-stomp/stomp_server_handler'
require 'vertx-stomp/stomp_server'
server = VertxStomp::StompServer.create(vertx).handler(VertxStomp::StompServerHandler.create(vertx)).listen(1234, "0.0.0.0")

----

If you pass `-1` as port, the TCP server would not be started. This is useful when using the websocket
bridge. To be notified when the server is ready, use a handler as follows:

[source,ruby]
----
require 'vertx-stomp/stomp_server_handler'
require 'vertx-stomp/stomp_server'
server = VertxStomp::StompServer.create(vertx).handler(VertxStomp::StompServerHandler.create(vertx)).listen() { |ar_err,ar|
  if (ar_err != nil)
    puts "Failing to start the STOMP server : #{ar_err.get_message()}"
  else
    puts "Ready to receive STOMP frames"
  end
}

----

The handler receive a reference on the `link:../../yardoc/VertxStomp/StompServer.html[StompServer]`.

You can also configure the host and port in `link:../dataobjects.html#StompServerOptions[StompServerOptions]`:

[source,ruby]
----
require 'vertx-stomp/stomp_server_handler'
require 'vertx-stomp/stomp_server'
server = VertxStomp::StompServer.create(vertx, {
  'port' => 1234,
  'host' => "0.0.0.0"
}).handler(VertxStomp::StompServerHandler.create(vertx)).listen()

----

=== Closing a STOMP server

STOMP servers are closed as follows:

[source,ruby]
----
server.close() { |ar_err,ar|
  if (ar_err == nil)
    puts "The STOMP server has been closed"
  else
    puts "The STOMP server failed to close : #{ar_err.get_message()}"
  end
}

----

=== Configuration

The `link:../dataobjects.html#StompServerOptions[StompServerOptions]` let you configure some aspects of the STOMP server.

First, the STOMP server is based on a
`link:../../yardoc/Vertx/NetServer.html[NetServer]`, so you can configure the underlying `link:../../yardoc/Vertx/NetServer.html[NetServer]` from
the `link:../dataobjects.html#StompServerOptions[StompServerOptions]`. Alternatively you can also pass the
`link:../../yardoc/Vertx/NetServer.html[NetServer]` you want to use:

[source,ruby]
----
require 'vertx-stomp/stomp_server_handler'
require 'vertx-stomp/stomp_server'
server = VertxStomp::StompServer.create(vertx, netServer).handler(VertxStomp::StompServerHandler.create(vertx)).listen()

----

The `link:../dataobjects.html#StompServerOptions[StompServerOptions]` let you configure:

* the host and port of the STOMP server - defaults to `0.0.0.0:61613`.
* whether or not the STOMP server is secured - defaults to `false`
* the max STOMP frame body - default to 10 Mb
* the maximum number of headers accepted in a STOMP frame - defaults to 1000
* the max length of a header line in a STOMP frame - defaults to 10240
* the STOMP heartbeat time - default to `1000, 1000`
* the supported STOMP protocol versions (1.0, 1.1 and 1.2 by default)
* the maximum number of frame allowed in a transaction (defaults to 1000)
* the size of the transaction chunk - defaults to 1000 (see
`link:../dataobjects.html#StompServerOptions#set_transaction_chunk_size-instance_method[transactionChunkSize]`)
* the maximum number of subscriptions a client can handle - defaults to 1000

The STOMP heartbeat is configured using a JSON object as follows:

[source,ruby]
----
require 'vertx-stomp/stomp_server_handler'
require 'vertx-stomp/stomp_server'
server = VertxStomp::StompServer.create(vertx, {
  'heartbeat' => {
    'x' => 1000,
    'y' => 1000
  }
}).handler(VertxStomp::StompServerHandler.create(vertx)).listen()

----

Enabling security requires an additional `link:../../yardoc/VertxAuthCommon/AuthProvider.html[AuthProvider]` handling the
authentication requests:

[source,ruby]
----
require 'vertx-stomp/stomp_server_handler'
require 'vertx-stomp/stomp_server'
server = VertxStomp::StompServer.create(vertx, {
  'secured' => true
}).handler(VertxStomp::StompServerHandler.create(vertx).auth_provider(provider)).listen()

----

More information about `link:../../yardoc/VertxAuthCommon/AuthProvider.html[AuthProvider]` is available
http://vertx.io/docs/#authentication_and_authorisation[here].

If a frame exceeds one of the size limits, the frame is rejected and the client receives an `ERROR` frame. As the
specification requires, the client connection is closed immediately after having sent the error. The same behavior
happens with the other thresholds.

=== Subscriptions

The default STOMP server handles subscription destination as opaque Strings. So it does not promote a structure
and it not hierarchic. By default the STOMP server follow a _topic_ semantic (so messages are dispatched to all
subscribers).

=== Type of destinations

By default, the STOMP server manages _destinations_ as topics. So messages are dispatched to all subscribers. You
can configure the server to use queues, or mix both types:

[source,ruby]
----
require 'vertx-stomp/destination'
require 'vertx-stomp/stomp_server_handler'
require 'vertx-stomp/stomp_server'
server = VertxStomp::StompServer.create(vertx).handler(VertxStomp::StompServerHandler.create(vertx).destination_factory(lambda { |v,name|
  if (name.start_with?("/queue"))
    return VertxStomp::Destination.queue(vertx, name)
  else
    return VertxStomp::Destination.topic(vertx, name)
  end
})).listen()

----

In the last example, all destination starting with `/queue` are queues while others are topics. The destination is
created when the first subscription on this destination is received.

A server can decide to reject the destination creation by returning `null`:

[source,ruby]
----
require 'vertx-stomp/destination'
require 'vertx-stomp/stomp_server_handler'
require 'vertx-stomp/stomp_server'
server = VertxStomp::StompServer.create(vertx).handler(VertxStomp::StompServerHandler.create(vertx).destination_factory(lambda { |v,name|
  if (name.start_with?("/forbidden"))
    return nil
  elsif (name.start_with?("/queue"))
    return VertxStomp::Destination.queue(vertx, name)
  else
    return VertxStomp::Destination.topic(vertx, name)
  end
})).listen()

----

In this case, the subscriber received an `ERROR` frame.

Queues dispatches messages using a round-robin strategies.

=== Providing your own type of destination

On purpose the STOMP server does not implement any advanced feature. IF you need more advanced dispatching policy,
you can implement your own type of destination by providing a `link:../../yardoc/VertxStomp/DestinationFactory.html[DestinationFactory]`
returning your own `link:../../yardoc/VertxStomp/Destination.html[Destination]` object.

=== Acknowledgment

By default, the STOMP server does nothing when a message is not acknowledged. You can customize this by
providing your own `link:../../yardoc/VertxStomp/Destination.html[Destination]` implementation.

The custom destination should call the

`link:../../yardoc/VertxStomp/StompServerHandler.html#on_ack-instance_method[onAck]`
and
`link:../../yardoc/VertxStomp/StompServerHandler.html#on_nack-instance_method[onNack]`
method in order to let the `link:../../yardoc/VertxStomp/StompServerHandler.html[StompServerHandler]` customizes the behavior:

[source,ruby]
----
require 'vertx-stomp/stomp_server_handler'
require 'vertx-stomp/stomp_server'
server = VertxStomp::StompServer.create(vertx).handler(VertxStomp::StompServerHandler.create(vertx).on_ack_handler() { |acknowledgement|
  # Action to execute when the frames (one in `client-individual` mode, several
  # in `client` mode are acknowledged.
}.on_nack_handler() { |acknowledgement|
  # Action to execute when the frames (1 in `client-individual` mode, several in
  # `client` mode are not acknowledged.
}).listen()

----

=== Customizing the STOMP server

In addition to the handlers seen above, you can configure almost all aspects of the STOMP server, such as the
actions made when specific frames are received, the `ping` to sent to the client (to implement the heartbeat).
Here are some examples:

[source,ruby]
----
require 'vertx-stomp/stomp_server_handler'
require 'vertx-stomp/stomp_server'
server = VertxStomp::StompServer.create(vertx).handler(VertxStomp::StompServerHandler.create(vertx).close_handler() { |connection|
  # client connection closed
}.begin_handler() { |frame|
  # transaction starts
}.commit_handler() { |frame|
  # transaction committed
}).listen()

----

Be aware that changing the default behavior may break the compliance with the STOMP specification. So, please look
at the default implementations.

== STOMP client

STOMP clients connect to STOMP server and can send and receive frames.

=== Creating a STOMP client

You create a `link:../../yardoc/VertxStomp/StompClient.html[StompClient]` instance with default options as follows:

[source,ruby]
----
require 'vertx-stomp/stomp_client'
client = VertxStomp::StompClient.create(vertx).connect() { |ar_err,ar|
  if (ar_err == nil)
    connection = ar

  else
    puts "Failed to connect to the STOMP server: #{ar_err.to_string()}"
  end
}

----

The previous snippet creates a STOMP client connecting to "0.0.0.0:61613". Once connected, you get a
`link:../../yardoc/VertxStomp/StompClientConnection.html[StompClientConnection]` that let you interact with the server. You can
configure the host and port as follows:

[source,ruby]
----
require 'vertx-stomp/stomp_client'
client = VertxStomp::StompClient.create(vertx).connect(61613, "0.0.0.0") { |ar_err,ar|
  if (ar_err == nil)
    connection = ar

  else
    puts "Failed to connect to the STOMP server: #{ar_err.to_string()}"
  end
}

----

To catch connection errors due to authentication issues, or whatever error frames sent by the server during
the connection negotiation, you can register a _error handler_ on the Stomp Client. All
connections created with the client inherit of the error handler (but can have their own):

[source,ruby]
----
require 'vertx-stomp/stomp_client'
client = VertxStomp::StompClient.create(vertx).error_frame_handler() { |frame|
  # Received the ERROR frame
}.connect(61613, "0.0.0.0") { |ar_err,ar|
  if (ar_err == nil)
    connection = ar

  else
    puts "Failed to connect to the STOMP server: #{ar_err.to_string()}"
  end
}

----

You can also configure the host and port in the `link:../dataobjects.html#StompClientOptions[StompClientOptions]`:

[source,ruby]
----
require 'vertx-stomp/stomp_client'
client = VertxStomp::StompClient.create(vertx, {
  'host' => "localhost",
  'port' => 1234
}).connect() { |ar_err,ar|
  if (ar_err == nil)
    connection = ar

  else
    puts "Failed to connect to the STOMP server: #{ar_err.to_string()}"
  end
}

----

=== Closing a STOMP client

You can close a STOMP client:

[source,ruby]
----
require 'vertx-stomp/stomp_client'
client = VertxStomp::StompClient.create(vertx, {
  'host' => "localhost",
  'port' => 1234
}).connect() { |ar_err,ar|
  if (ar_err == nil)
    connection = ar

  else
    puts "Failed to connect to the STOMP server: #{ar_err.to_string()}"
  end
}

client.close()

----

However, this way would not notify the server of the disconnection. To cleanly close the connection, you should
use the `link:../../yardoc/VertxStomp/StompClientConnection.html#disconnect-instance_method[disconnect]` method:

[source,ruby]
----
require 'vertx-stomp/stomp_client'
client = VertxStomp::StompClient.create(vertx, {
  'host' => "localhost",
  'port' => 1234
}).connect() { |ar_err,ar|
  if (ar_err == nil)
    connection = ar

    connection.disconnect()
  else
    puts "Failed to connect to the STOMP server: #{ar_err.to_string()}"
  end
}

----

If the heartbeat is enabled and if the client did not detect server activity after the configured timeout, the
connection is automatically closed.

=== Handling errors

On the `link:../../yardoc/VertxStomp/StompClientConnection.html[StompClientConnection]`, you can register an error handler receiving `ERROR`
frames sent by the server. Notice that the server closes the connection with the client after having sent such frame:

[source,ruby]
----
require 'vertx-stomp/stomp_client'
client = VertxStomp::StompClient.create(vertx, {
  'host' => "localhost",
  'port' => 1234
}).connect() { |ar_err,ar|
  if (ar_err == nil)
    connection = ar
    connection.error_handler() { |frame|
      puts "ERROR frame received : #{frame}"
    }
  else
    puts "Failed to connect to the STOMP server: #{ar_err.to_string()}"
  end
}

----

The client can also be notified when a connection drop has been detected. Connection failures are detected using the
STOMP heartbeat mechanism. When the server has not sent a message in the heartbeat time window, the connection is
closed and the `connectionDroppedHandler` is called (if set). To configure a `connectionDroppedHandler`, call
`link:../../yardoc/VertxStomp/StompClientConnection.html#connection_dropped_handler-instance_method[connectionDroppedHandler]`. The handler can
for instance tries to reconnect to the server:

[source,ruby]
----
require 'vertx/buffer'
require 'vertx-stomp/stomp_client'
client = VertxStomp::StompClient.create(vertx).connect() { |ar_err,ar|
  if (ar_err == nil)
    connection = ar
    connection.connection_dropped_handler() { |con|
      # The connection has been lost
      # You can reconnect or switch to another server.
    }

    connection.send("/queue", Vertx::Buffer.buffer("Hello")) { |frame|
      puts "Message processed by the server"
    }
  else
    puts "Failed to connect to the STOMP server: #{ar_err.to_string()}"
  end
}

----

=== Configuration

You can configure various aspect by passing a
`link:../dataobjects.html#StompClientOptions[StompClientOptions]` when creating the `link:../../yardoc/VertxStomp/StompClient.html[StompClient]`. As the
STOMP client relies on a `link:../../yardoc/Vertx/NetClient.html[NetClient]`, you can configure the underlying Net Client from
the `link:../dataobjects.html#StompClientOptions[StompClientOptions]`. Alternatively, you can pass the `link:../../yardoc/Vertx/NetClient.html[NetClient]`
you want to use in the
`link:../../yardoc/VertxStomp/StompClient.html#connect-instance_method[connect]` method:

[source,ruby]
----
require 'vertx-stomp/stomp_client'
client = VertxStomp::StompClient.create(vertx).connect(netClient) { |ar_err,ar|
  if (ar_err == nil)
    connection = ar
    connection.error_handler() { |frame|
      puts "ERROR frame received : #{frame}"
    }
  else
    puts "Failed to connect to the STOMP server: #{ar_err.to_string()}"
  end
}

----

The `link:../dataobjects.html#StompClientOptions[StompClientOptions]` let you configure:

* the host and port ot the STOMP server
* the login and passcode to connect to the server
* whether or not the `content-length` header should be added to the frame if not set explicitly. (enabled by default)
* whether or not the `STOMP` command should be used instead of the `CONNECT` command (disabled by default)
* whether or not the `host` header should be ignored in the `CONNECT` frame (disabled by default)
* the heartbeat configuration (1000, 1000 by default)

=== Subscribing to destinations

To subscribe to a destination, use:

[source,ruby]
----
require 'vertx-stomp/stomp_client'
client = VertxStomp::StompClient.create(vertx).connect() { |ar_err,ar|
  if (ar_err == nil)
    connection = ar
    connection.subscribe("/queue") { |frame|
      puts "Just received a frame from /queue : #{frame}"
    }
  else
    puts "Failed to connect to the STOMP server: #{ar_err.to_string()}"
  end
}

----

To unsubscribe, use:

[source,ruby]
----
require 'vertx-stomp/stomp_client'
client = VertxStomp::StompClient.create(vertx).connect() { |ar_err,ar|
  if (ar_err == nil)
    connection = ar
    connection.subscribe("/queue") { |frame|
      puts "Just received a frame from /queue : #{frame}"
    }

    # ....

    connection.unsubscribe("/queue")
  else
    puts "Failed to connect to the STOMP server: #{ar_err.to_string()}"
  end
}

----

=== Sending messages

To send a message, use:

[source,ruby]
----
require 'vertx/buffer'
require 'vertx-stomp/stomp_client'
client = VertxStomp::StompClient.create(vertx).connect() { |ar_err,ar|
  if (ar_err == nil)
    connection = ar
    headers = Hash.new()
    headers["header1"] = "value1"
    connection.send("/queue", headers, Vertx::Buffer.buffer("Hello"))
    # No headers:
    connection.send("/queue", Vertx::Buffer.buffer("World"))
  else
    puts "Failed to connect to the STOMP server: #{ar_err.to_string()}"
  end
}

----



=== Acknowledgements

Clients can send `ACK` and `NACK` frames:

[source,ruby]
----
require 'vertx-stomp/stomp_client'
client = VertxStomp::StompClient.create(vertx).connect() { |ar_err,ar|
  if (ar_err == nil)
    connection = ar
    connection.subscribe("/queue") { |frame|
      connection.ack(frame['ack'])
      # OR
      connection.nack(frame['ack'])
    }
  else
    puts "Failed to connect to the STOMP server: #{ar_err.to_string()}"
  end
}

----

=== Transactions

Clients can also create transactions. `ACK`, `NACK` and `SEND` frames sent in the transaction will be delivery
only when the transaction is committed.

[source,ruby]
----
require 'vertx/buffer'
require 'vertx-stomp/stomp_client'
client = VertxStomp::StompClient.create(vertx).connect() { |ar_err,ar|
  if (ar_err == nil)
    connection = ar
    headers = Hash.new()
    headers["transaction"] = "my-transaction"
    connection.begin_tx("my-transaction")
    connection.send("/queue", headers, Vertx::Buffer.buffer("Hello"))
    connection.send("/queue", headers, Vertx::Buffer.buffer("World"))
    connection.send("/queue", headers, Vertx::Buffer.buffer("!!!"))
    connection.commit("my-transaction")
    # OR
    connection.abort("my-transaction")
  else
    puts "Failed to connect to the STOMP server: #{ar_err.to_string()}"
  end
}

----

=== Receipt

Each sent commands can have a _receipt_ handler, notified when the server has processed the message:

[source,ruby]
----
require 'vertx/buffer'
require 'vertx-stomp/stomp_client'
client = VertxStomp::StompClient.create(vertx).connect() { |ar_err,ar|
  if (ar_err == nil)
    connection = ar

    connection.send("/queue", Vertx::Buffer.buffer("Hello")) { |frame|
      puts "Message processed by the server"
    }
  else
    puts "Failed to connect to the STOMP server: #{ar_err.to_string()}"
  end
}

----

== Using the STOMP server as a bridge to the vert.x Event Bus

The STOMP server can be used as a bridge to the vert.x Event Bus. The bridge is bi-directional meaning the STOMP
frames are translated to Event Bus messages and Event Bus messages are translated to STOMP frames.

To enable the bridge you need to configure the inbound and outbound addresses. Inbound addresses are STOMP
destination that are transferred to the event bus. The STOMP destination is used as the event bus address. Outbound
addresses are event bus addresses that are transferred to STOMP.

[source,ruby]
----
require 'vertx-stomp/stomp_server_handler'
require 'vertx-stomp/stomp_server'
server = VertxStomp::StompServer.create(vertx).handler(VertxStomp::StompServerHandler.create(vertx).bridge({
  'inboundPermitteds' => [
    {
      'address' => "/toBus"
    }
  ],
  'outboundPermitteds' => [
    {
      'address' => "/toStomp"
    }
  ]
})).listen()

----

By default, the bridge use a publish/subscribe delivery (topic). You can configure it to use a point to point
delivery where only one STOMP client or Event Bus consumer is invoked:

[source,ruby]
----
require 'vertx-stomp/stomp_server_handler'
require 'vertx-stomp/stomp_server'
server = VertxStomp::StompServer.create(vertx).handler(VertxStomp::StompServerHandler.create(vertx).bridge({
  'inboundPermitteds' => [
    {
      'address' => "/toBus"
    }
  ],
  'outboundPermitteds' => [
    {
      'address' => "/toStomp"
    }
  ],
  'pointToPoint' => true
})).listen()

----

The permitted options can also be expressed as a "regex" or with a _match_. A _match_ is a structure that the
message payload must meet. For instance, in the next examples, the payload must contains the field "foo" set to
"bar". Structure match only supports JSON object.

[source,ruby]
----
require 'vertx-stomp/stomp_server_handler'
require 'vertx-stomp/stomp_server'
server = VertxStomp::StompServer.create(vertx).handler(VertxStomp::StompServerHandler.create(vertx).bridge({
  'inboundPermitteds' => [
    {
      'address' => "/toBus",
      'match' => {
        'foo' => "bar"
      }
    }
  ],
  'outboundPermitteds' => [
    {
      'address' => "/toStomp"
    }
  ],
  'pointToPoint' => true
})).listen()

----

== Using the STOMP server with web sockets

If you want to connect a JavaScript client (node.js or a browser) directly with the STOMP server, you can use a
web socket. The STOMP protocol has been adapted to work over web sockets in
http://jmesnil.net/stomp-websocket/doc/[StompJS]. The JavaScript connects directly to the STOMP server and send
STOMP frames on the web socket. It also receives the STOMP frame directly on the web socket.

To configure the server to use StompJS, you need to:

1. Enable the web socket bridge and configure the path of the listening web socket (`/stomp` by default).
2. Import http://jmesnil.net/stomp-websocket/doc/#download[StompJS] in your application (as a script on an
HTML page, or as an npm module (https://www.npmjs.com/package/stompjs).
3. Connect to the server

To achieve the first step, you would need a HTTP server, and pass the
`link:../../yardoc/VertxStomp/StompServer.html#web_socket_handler-instance_method[webSocketHandler]` result to
`link:../../yardoc/Vertx/HttpServer.html#websocket_handler-instance_method[websocketHandler]`:

[source,ruby]
----
require 'vertx-stomp/stomp_server_handler'
require 'vertx-stomp/stomp_server'
server = VertxStomp::StompServer.create(vertx, {
  'port' => -1,
  'websocketBridge' => true,
  'websocketPath' => "/stomp"
}).handler(VertxStomp::StompServerHandler.create(vertx))

http = vertx.create_http_server({
  'websocketSubProtocols' => "v10.stomp, v11.stomp"
}).websocket_handler(&server.web_socket_handler()).listen(8080)

----

Don't forget to declare the supported sub-protocols. Without this, the connection will be rejected.

Then follow the instructions from  http://jmesnil.net/stomp-websocket/doc/[the StompJS documentation] to connect to
the server. Here is a simple example:

[source, javascript]
----
var url = "ws://localhost:8080/stomp";
var client = Stomp.client(url);
var callback = function(frame) {
  console.log(frame);
};

client.connect({}, function() {
var subscription = client.subscribe("foo", callback);
});
----

== Registering received and writing frame handlers

STOMP clients, client's connections and server handlers support registering a received
`link:../dataobjects.html#Frame[Frame]` handler that would be notified every time a frame is received from the wire. It lets
you log the frames, or implement custom behavior. The handler is already called for `PING`
frames, and _illegal / unknown_ frames:

[source,ruby]
----
require 'vertx-stomp/stomp_server_handler'
require 'vertx-stomp/stomp_server'
require 'vertx-stomp/stomp_client'
server = VertxStomp::StompServer.create(vertx).handler(VertxStomp::StompServerHandler.create(vertx).received_frame_handler() { |sf|
  puts sf.frame()
}).listen()

client = VertxStomp::StompClient.create(vertx).received_frame_handler() { |frame|
  puts frame
}

----

The handler is called before the frame is processed, so you can also _modify_ the frame.

Frames not using a valid STOMP command use the `UNKNOWN` command. The original command is written
in the headers using the `link:todo[Frame.STOMP_FRAME_COMMAND]` key.

You can also register a handler to be notified when a frame is going to be sent (written to the wire):

[source,ruby]
----
require 'vertx-stomp/stomp_server_handler'
require 'vertx-stomp/stomp_server'
require 'vertx-stomp/stomp_client'
server = VertxStomp::StompServer.create(vertx).handler(VertxStomp::StompServerHandler.create(vertx)).writing_frame_handler() { |sf|
  puts sf.frame()
}.listen()

client = VertxStomp::StompClient.create(vertx).writing_frame_handler() { |frame|
  puts frame
}

----