SMQ Cluster Management

Clustering can be used for the following:

Enabling clustering is best illustrated with an example:

ccm,err=require"smq.clustercon".create(cluster, 1900)
if ccm then
   --Cluster nodes. Use names if you have DNS
   local list={"","", ""}
   ccm.setlist(list) -- Connect the nodes

SMQ Cluster Manager

The Cluster Manager adds clustering support for the SMQ broker thus enabling any number of SMQ brokers to scale up horizontally.

The Cluster Manager is typically used in combination with the Cluster Connection Manager; however, the Cluster Manager can also be used directly if a more exotic clustering configuration is required than what can be provided by the Cluster Connection Manager. An example of such a connection configuration can be found in the example below. You can also combine the use of a Cluster Connection Manager with your own connection manager.

The following example shows how to establish a cluster connection by initially using HTTP. You can also establish an HTTPS connection by using an https:// URL and/or use the proxy/tunneling settings available to the HTTP client library.

Common code required by both client and server code below (in a .preload/.config script).

HTTP client in .preload/.config scriptServer LSP Page
local http=require"httpc".create()
if http:status() == 204 then
if request:header"SMQ" == "CLUSTER" then

References: Module httpc, ba.socket.http2sock, ba.socket.req2sock

SMQ Cluster Manager API

create(smq [,password])

Creates and returns an SMQ Cluster Manager instance: require"smq.clustermgr".create(smq)

cluster.commence(sock [,onclose [,onconnect]])

Start the initial handshake with the peer and commence normal operation if the handshaking succeeds.


Shuts down operation by closing all active cluster connections.

Advanced Functions

cluster.publish(data, [ptid,] subtopic)

Publish a message to the server SMQ client (server's ephemeral TID). The message is published to all connected cluster nodes. The function returns the number of sent messages -- i.e. the number of connected cluster nodes.

cluster.pubon(data, ptid, topic, subtopic)

Publish on behalf of 'ptid'.

SMQ Cluster Connection Manager

The Cluster Connection Manager (CCM) automates the connection of cluster nodes. The CCM takes a list of names or IP addresses and attempts to connect to the remote clusters. The CCM also acts as a server and waits for other CCMs to connect. When a connection is established -- i.e. when a client or server socket object is created, function cluster.commence is called and the socket object is passed into the Cluster Manager. The CCM automatically attempts to reconnect broken connections.

One can manually add cluster names or ip-addresses to the CCM one at a time or one can set a pre-defined list. The CCM is designed to detect addresses pointing to 'self'. This construction makes it possible to use the same list on all cluster nodes.

create(clustermgr, port [,op])

Creates and returns an SMQ Cluster Connection Manager instance: require"smq.clustercon".create(clustermgr, 1999)

One can create multiple CCMs for the same Cluster Manager instance. One CCM may, for example, establish non secure communication links and another may establish secure (TLS) communication links.

The connections are, by default, non secure. To enable secure communication (TLS), set op.shark to a SharkSSL client object and op.sshark to a SharkSSL server object. You must also setup a certificate for the SharkSSL server object and a certificate store for the SharkSSL client object. The signer (CA cert) of the server certificate must be added to the client's certificate store. Non trusted connections are closed by the client.

ccm.add(addr [,port])

Add one cluster node. One can call this function repeatably and one can also add nodes already registered.


Set, replace, or remove the registered cluster nodes. An existing list can be removed by providing an empty table {}.

Closes the server listening socket and shuts down operation. Shutting down operation does not affect active connections in the Cluster Manager.