Achieve Fault Tolerant Messaging with MQ Gateway
Learn how you can achieve fault tolerant messaging using the MQ Gateway feature of JBoss Fuse 6.2 to provide a single IP and port to accept connections from clients.
Join the DZone community and get the full member experience.Join For Free
Sometime ago I posted a blog about achieving fault tolerant messaging; in the article, I mention using fabric registry discovery to hide all the IP address and port details in the client side. With new Fuse 6.2, you will not be able to find this anymore. So how do we achieve fault tolerant messaging in the new Fuse?
In JBoss Fuse 6.2, we can do it by starting up a MQ Gateway. What it does is it provides a single IP and port to accept connections from clients. All the individual IPs and Port of the broker are hidden away tothe client, the client only needs to know the IP and port of the MQ Gateway (Default Port: 61616). The gateway will discover all the brokers in the fabric, and no matter what the incoming protocol is, it can be OpenWire, MQTT, STOMP and AMQP. The gateway will see which broker is available in the host specified for the protocol, and connect the client to the broker. If multiple brokers are available in the host group, gateway can dispatch request to them, by this we can achieve load balance. There are 3 different way to do load balance, Random, Round Robin and Sticky.
If any thing goes wrong with the broker a client is connecting, and got disconnected, the gateway will look for another available broker in the group. This gives you high availability to your service.
To startup a MQ Gateway, simply choose the gateway-mq profile to the container.
It will automatically find brokers in fabric:
I updated my failover demo instead of using fabric registry discovery, I change my application and connect it to MQ Gateway. In this demo, you will first need to create a broker failoverMS, choose Master/Slave type and use blogdemo as Group.
Click on the red triangle to start provision the brokers. It will take you yo the page to create container for the broker profile.
And will start create number of container you specified in the configuration.
Then we can startup the MQ-Gateway, before we do that, go to the gateway-mq profile and edit the io.fabric8.gateway.detecting.properties file. Change port to 8888 and defaultVirtualHost to blogdemo.
And add the gateway-mq profile to a container, as previously stated.
Let's take a look at the client application, it's written with Camel. Look at the configurations in the Camel route, here you see no matter if it's an OpenWire or MQTT protocol, it is set to tcp://localhost:8888, which is the IP and port of MQ Gateway.
This application send a message to the broker, through OpenWire and MQTT protocol every 5 secs. Deploy the profile "" to a new container.
Go to container console of testcon, you will find the camel routes are running.
In the MQ Gateway, you can see the request was dispatched to the broker we have created.
And the messages was sent to broker.
Video can be found here.
The application code can be found here.
Published at DZone with permission of Christina Lin, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.