Skip to content

Handling Errors

Konstantin Chukhlomin edited this page Sep 5, 2015 · 1 revision

Synchronous Operations

By default this client is configured to work in a synchronous mode, which means that for every command (except CONNECT) the client will wait for the receipt. You can set the client to work in the asynchronous mode, by setting the sync property of the StompConnection object to false.

$stomp = new Stomp("tcp://localhost:61613");
$stomp->sync = false;

You can also perform single operations in desired mode, no matter of the global client settings, by passing additional parameter to the appropriate method

$stomp->send('/queue/test', 'test', null, true);

Some things you have to consider when deciding whether to use synchronous or asynchronous mode:

  • When you use asynchronous mode broker errors will be ignored
  • Asynchronous method allows you to send messages faster, since will not wait for broker's response

Exceptions

Basically there are two kind of errors you can experience when using this client: errors while trying to connect to a broker and errors after sending a certain command to the broker (like authorization errors for example).

Broker Errors

In case you use the client (or at least the current operation) in a synchronous mode, the client will wait for the broker to send a receipt for every synchronous command. In case that error is received instead of the receipt, the client will throw StompException. In case you have sent a command in an asynchronous mode the errors will be ignored. The more examples on how to handle exception will be shown in the following section.