We already have our MQ server running, now lets install our first DB Cluster by following my tutorials in setting up MySQL Cluster, starts from here.
Assumed that we successfully installed our DB Cluster, before we start writing codes of our DB 2 MQ Connectors, lets go back to the requirements, then move to the connectors design.
A. Requirements:
- I want to distribute and spread all users’ session into many sharded DB servers equally, meaning: I want the first user session that logged-in into my Application to be persisted in my 1st DB Cluster, the next logged-in user will goes to the 2nd DB Cluster and so on. When the last of my DB Cluster instance reached, the next logged-in user will goes back to the 1st DB Cluster, in other words: I want to spread the load equally to all my DB Cluster instances by doing a round robin,
- I want my Application to be able to selects, updates and deletes a user’s session, without any knowledge: in which DB Cluster instance that user is registered.
By using features of the RabbitMQ, the above requirements are easy to be done, so before we move on, there are some prerequisites knowledge we must acquired regarding:
- Work queues message routing in RabbitMQ,
- Publish/subscribe message routing in RabbitMQ, and
- Topic message routing in (again) RabbitMQ
Please do learn all those features listed above, in order to understand the codes we are going to do in the next steps.
B. Connector Design for Handling “INSERT” Data
Our first DB 2 MQ Connector is for handling data insertion. For data insertion, we are going to use the same approached with the Work queues message routing example. This way, our requirement to equally spreads the load to all available DB Cluster instances can be achieved. This concept can be illustrated as below pic.
C. Connector Design for Handling “SELECT, UPDATE and DELETE” Data
Our second DB 2 MQ Connector is for handling data selection, updates and deletion. For doing these db operations, we are going to use the same approached with the Publish/subscribe message routing example, with FANOUT mode. This way, our requirement on hiding where the required data is resides from my Application can be achieved. This concept can be illustrated as below pic.
D. Connector Design for Returning “SELECT” Result
Our third or last DB 2 MQ Connector is for returning a result set on data selection operation. For doing this, we are going to use the same approached with the Topic message routing example. This way, each of our DB Cluster instance can return the selection result to the right Application instance. This concept can be illustrated as below pic.
Ok that’s it guys… next, I’m going to introduce how to use both Java AMQP client library and ClusterJ, for developing our DB 2 MQ Connectors, as I designed above.