gdaws/stompit

Error on send?

Closed this issue · 3 comments

If I disable our ActiveMQ bus, then attempt to use stompit to send a message to the bus, it doesn't throw any sort of error, despite the message obviously not making it to the bus.

Is there any error handling built into the send method? Or is there any way of knowing if your message errored out or not?

gdaws commented

If you're using the client API, a client object (which extends EventEmitter) emits an error event when it attempts to send a frame to the server and fails because of a transport error.

If you're using the channel API with the default reconnect configuration then the send operation is delayed until a connection is established and delivery is made. The channel will wait indefinitely to reconnect.

It's a toughy because, let's say I have an API in front of my bus as an abstraction layer - if I want to send a HTTP response code based on the success of that message, it isn't the easiest thing to do. It would be preferable if errors propagated their way up (possibly as the result of a config param).

gdaws commented

Errors can be propagated to the send message call site by using callback functions.

client.send(headers, {
  onError: (error) => {/* handle error */}, 
  onReceipt: () => {/* handle success */}
});

or:

channel.send(headers, body, (error) => {

  if (error) {
     // handle error
     return;
  }

  // handle success
});