Wednesday, February 15, 2012

ZooKeeper Increase maximum number of connections

When using zookeeper you may get the following exception:

org.apache.zookeeper.KeeperException$ConnectionLossException:
KeeperErrorCode = ConnectionLoss for /foo.XXXXXXXX
at org.apache.zookeeper.KeeperException.create(KeeperException.java

At the same time if you view the log of zookeeper you will see the the following warning :

WARN org.apache.zookeeper.server.NIOServerCnxn: Too many connections from /127.0.0.1 - max is 10

This is due to the default maximum number of connections configured in zookeeper.

You can overcome this by setting up the maximum number of connections in zoo keeper configuration file.(conf/zoo.cfg)

Add following entry to zoo.cfg file and restart zooKeeper. It will set maximum number of connections to 30.

"maxClientCnxns=30"

Killing multiple java processes at once

There are situations we need to kill multiple java processes at once. We can do it by killing all java processes. But there may be requirements to kill some filtered out java processes.

Lets say i have some processes which are running with details "OnceInOrderLoadTest.jar". I can kill all processes running with that details as bellow.


ps ax | grep OnceInOrderLoadTest.jar |grep -v grep | awk '{print $1}'| xargs kill -9

Wednesday, February 8, 2012

SQS Client for Stratos Live

It is a great advantage , if we can test message box feature of wso2 message broker in stratos live environment since it takes some time to set up product locally and test. Here i am going to describe how we can use a java client to invoke message box feature which acts as a message store of Wso2 Message broker in stratos live environment.

We can find the sample on creating "SQS SOAP Client" in here. This sample is specifically written for standalone product testing.

For stratos testing there are only few things need to be changed in this sample.

As described in the above sample as the first step you need to generate the code for the SQS wsdl.

For that you have multiple ways,
1. Use Axis2 wsdl2java tool for code generation
You can find samples on how to do that here.

2. Use wsdl2java feature of any of the wso2 products and generate the code from that.

Once you generate the code with using one of the above two methods, you can create a project using those source files.


If it is not automatically added the required libraries to the class path of your project, you need to add the libraries to the class path.

You can find all the required libraries for this source code in Message Broker product.
what you need to do is;

1. Extract wso2mb-1.0.2.zip
2. go to wso2mb-1.0.2/bin folder and run "ant" command
3. This will create a lib folder in "wso2mb-1.0.2/repository/" folder
4. You can add this lib folder to your class path

Once you have created the project successfully, you can use the same client for invoking Stratos Live Message Broker. How ever before invoking the client, you need to do some changes in that client code.

You need to change following constant of that client;
Eg: For the tenant foo.com , EPR will be

public static final String EPR = "http://messaging.stratoslive.wso2.com/services/a/foo.com/QueueService";

Apart from that you need to get the "accessKey" and the "secretAccessKey" after log in to the Message Broker service.

With changing those constants , you will be able to use the message box feature of Stratos Message Broker Service successfully.

Monday, October 17, 2011

Transport error occurred during acceptance of message. org.apache.thrift.transport.TTransportException: java.net.SocketException: Too many open files


WARN 13:59:01,693 Transport error occurred during acceptance of message.
org.apache.thrift.transport.TTransportException: java.net.SocketException: Too many open files\



This is a common error occurs when using cassandra. This is caused due to the file limit of the system. To overcome this problem , we need to increase the file limit of the system.

you can follow this post to increase the file limit and it will solve this problem.

Tuesday, October 11, 2011

Sample Java client for RabbitMQ

Here you can find sample java client for RabbitMQ. I have taken this from Programming fun at startup blog. I have tried this and working
fine with out any issue.


Steps to follow :

1. Install RabbitMQ server : http://www.rabbitmq.com/install.html#debian

2. Download RabbitMQ client libraries : http://www.rabbitmq.com/java-client.html

3. Start the installed RabbitMQ Server

4. Use the downloaded client libraries for the following consumer and the sender.

5. Start the consumer first and then the Producer


-------------------RabbitMQProducer.java-----------------------------


import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.*;

public class RabbitMQProducer {
public static void main(String []args) throws Exception {
ConnectionFactory factory = new ConnectionFactory();
factory.setUsername("guest");
factory.setPassword("guest");
factory.setVirtualHost("/");
factory.setHost("127.0.0.1");
factory.setPort(5672);
Connection conn = factory.newConnection();
Channel channel = conn.createChannel();
String exchangeName = "myExchange";
String routingKey = "testRoute";
byte[] messageBodyBytes = "Hello, world!".getBytes();
channel.basicPublish(exchangeName, routingKey
,MessageProperties.PERSISTENT_TEXT_PLAIN, messageBodyBytes) ;
channel.close();
conn.close();
}
}

----------------------RabbitMQConsumer.java----------------------------------


import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.*;
public class RabbitMQConsumer {
public static void main(String []args) throws Exception {
ConnectionFactory factory = new ConnectionFactory();
factory.setUsername("guest");
factory.setPassword("guest");
factory.setVirtualHost("/");
factory.setHost("127.0.0.1");
factory.setPort(5672);
Connection conn = factory.newConnection();
Channel channel = conn.createChannel();
String exchangeName = "myExchange";
String queueName = "myQueue";
String routingKey = "testRoute";
boolean durable = true;
channel.exchangeDeclare(exchangeName, "direct", durable);
channel.queueDeclare(queueName, durable,false,false,null);
channel.queueBind(queueName, exchangeName, routingKey);
boolean noAck = false;
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(queueName, noAck, consumer);
boolean runInfinite = true;
while (runInfinite) {
QueueingConsumer.Delivery delivery;
try {
delivery = consumer.nextDelivery();
} catch (InterruptedException ie) {
continue;
}
System.out.println("Message received"
+ new String(delivery.getBody()));
channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
}
channel.close();
conn.close();
}
}


Another nice article on this can be found here.

Tuesday, September 27, 2011

How to wrap the maven script with ant ?

Most of the time people need to do the other way around.
That mean to wrap ant scripts with maven scripts. But ,
in some rare situations there are people who want to wrap
maven scripts with ant scripts.

It is very easy to do this. You need to have maven
installed and set the MVN_HOME for this.


<project default="buildProject">
  <property name="source.dir" value="."/>
<target name="buildProject" description="Wrapper for the maven script">
<exec dir="${source.dir}" executable="mvn">
<arg line="clean install" />
</exec>
</target>
</project>


place this code segment in your build.xml file. Place
that build.xml file in the folder which you have the
maven script (pom.xml). Go to the folder with command
prompt. Execute "ant" command. Thats all...!