How to use the RabbitMQ Web-Stomp Plugin with Delphi and Free Pascal

The RabbitMQ open source message broker includes a web-stomp plugin exposing the STOMP protocol over emulated HTML5 WebSockets. Web-Stomp examples are provided as a plugin which is included in the standard distribution and only needs to be enabled (this requires a broker restart).

For users of the Delphi and Free Pascal client library Habari Client for RabbitMQ, the echo demo, which shows how to use STOMP to do simple message broadcasting, had a small problem: while text sent from the Delphi / Free Pascal side correctly appeared in the browser chat window, text entered in the browser did not reach the Delphi / Free Pascal application.

The reason was a missing STOMP header, content-type. The STOMP specification states that in this case “the receiver SHOULD consider the body to be a binary blob”, and so the chat message will not be treated as a text message.

A change is planned in the RabbitMQ side which will cause the content-type:plain/text message frame to be present. Until its release, Delphi and Free Pascal can use a workaround and convert the binary message content to a string, using UTF8Decode or UTF8ToString.

Hint: the Habari Chat demo application can be used to try the web stomp plugin. Simply use ‘test’ as the chat room name.