This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • WebSockets
Skip to end of metadata
Go to start of metadata

Introduction

Besides Ajax API, starting with version 5.4.0 onwards, you can use HTML5 WebSockets to exchange messages with the broker from your browser.

HTML 5 introduced web sockets, as a standardized way to communicate asynchronously with the server from a web page. This is practically an ideal channel for implementing asynchronous messaging for web pages. Since JavaScript easily handles text and JSON formatted data, Stomp protocol is a good choice for the wire protocol to be used over web sockets. Since version 5.9.0, we also support efficient binary MQTT protocol over Web sockets.

This solution should bring better messaging capabilities to JavaScript clients then simple Ajax API, as implementing Stomp or MQTT in JavaScript brings much more messaging-oriented API and features such as transactions, for example.

Configuration

ActiveMQ comes with WebSocket transport which implements Stomp over WebSockets functionality.

To configure it, you need to place something like this to your ActiveMQ configuration file

<transportConnectors>
  <transportConnector name="websocket" uri="ws://0.0.0.0:61614"/>
</transportConnectors>

One thing worth noting is that web sockets (just as Ajax) implements the same origin policy, so you can access only brokers running on the same host as the web application running the client.

Secure Web Sockets

Version 5.7.0 introduced Secure Web Socket transport. To configure it you need two things. First, you need to configure a new transport connector like this

<transportConnectors>
  <transportConnector name="secure_websocket" uri="wss://0.0.0.0:61614"/>
</transportConnectors>

Note that we use wss url prefix to denote a secured version of the protocol. Next you need to provide SSL context for this transport. You can do that by providing sslContext in your broker configuration in a similar fashion as you'd do for ssl or https transports.

<sslContext>
    <sslContext keyStore="file:${activemq.conf}/broker.ks"
                keyStorePassword="password" trustStore="file:${activemq.conf}/broker.ts"
                trustStorePassword="password"
    />
</sslContext>

That's it, your secure websocket transport is ready. Take a look at the next section to see how to use a demo to test it out.

Demos

As of version 5.6.0, an adapted demo of stomp-websocket library is integrated with ActiveMQ web demo application.
As of version 5.9.0, we have a similar demo using MQTT and Eclipse Paho client

To see demos:

Clients

More Resources

  • No labels