Chapter 5. Beyond STOMP

STOMP provides a simple yet flexible messaging protocol. It also offers an extensible way for brokers to provide additional features beyond the ones specified in the protocol.

In this chapter, we will show how to leverage broker features with STOMP headers. Until this chapter, all STOMP brokers could be used to send and receive messages from our applications; but in this chapter, you will have to check your broker documentation to see if it provides these features (or others not covered by this chapter).

Message Persistence

Some STOMP brokers support persistent messages to ensure that if a message is held by the broker when it crashes, the message will be persisted (which means stored on a durable support) so that the broker can fetch it when it restarts and handle it again. This prevents data loss (at the cost of performance, because the broker must ensure that the message is effectively written on the storage support). To use persistent messages, most STOMP brokers (including ActiveMQ) require that the message be sent with a persistent header set to true.

In the Locations application, we send two types of messages: one for the device location and one for text messages.

The location messages do not need to be persisted and survive a broker crash. There are minimal consequences if these messages are lost if the broker crashed. Once the broker is up again, the device will send an updated position.

However, for the text messages sent to the devices, we want ...

Get Mobile and Web Messaging now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.