[rabbitmq-discuss] Help,question about rabbitmq+Haproxy,client java

Aaron 584911644 at qq.com
Tue Jul 22 08:53:45 BST 2014

I have let only one node  rabbitmq online in my company in order to decoupling messages.‍    This node has not been down for almost one month fortunately?but some basic problem,such as the HA and Load balancing need to be considered,so that  can keep all messages complete no matter when the related server or app is down.Such like,another node will  work still and keep the produce、customer healthy when a node is down.
    So,i have considered a solution to protect from losting messages,it‘s rabbitmq(mirrored queue)+Haproxy.
    I have tried two different code,php  plays a role,both HA and load balancing.
    But,java code is not enough fortunately,LOL... Testing for several times,and I get a result,that is java code doesn‘t work at all in HA,but only load balancing....,during testing,when I down a random node,producer will throw out a related session error.
    Having troubled me for almost one week this problem,and looking  sincerely forward to ur reply. 
    The environment will be shown below:
rabbit at ubuntu :
rabbit at ubuntu2:

PHP code: 

$n = 100000;
echo '<br/>'.$i;
$conn_args = array( 'host'=>'' , 'port'=> '5670', 'login'=>'aaron' , 'password'=> '5555','vhost' =>'/');
$conn = new AMQPConnection($conn_args);

$channel = new AMQPChannel($conn);
$ex = new AMQPExchange($channel);

$q = new AMQPQueue($channel);

$q->bind('direct_exchange_name', 'routingkey_name');

$message = json_encode(array('Hello World!','1','2','3','4','DIRECT'));
$ex->publish($message, 'routingkey_name');


JAVA code:
ConnectionFactory factory = new ConnectionFactory();// 创建链接工厂

		Connection connection = factory.newConnection();// 创建链接
		for(int i = 0; i < 10000; i++) {
			Channel channel = connection.createChannel();// 创建信息通道
			channel.exchangeDeclare(EXCHANGE_NAME, "fanout", durable);// 创建交换机并生命持久化
			String message = "Hello Wrold " + Math.random();
			// 消息的持久化
			channel.basicPublish(EXCHANGE_NAME, "",
					MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());
			System.out.println("[x] Sent '" + message + "'");

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20140722/27fb9aae/attachment.html>

More information about the rabbitmq-discuss mailing list