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...!

Thursday, September 22, 2011

error=24, Too many open files

Many users have experience in getting this error when building with maven.

The way to over come this problem is to increase the file limit of the OS.

First, in order to set this options automatically you have to edit the etc/security/limits.conf file.

$sudo gedit /etc/security/limits.conf

with the above command you can open the "limits.conf" file with gedit.
We need to set the nofile option meaning maximum number of open files.If you want to change the number of files of user, you should add this line in the limits.conf file.

Lets say our user name is "foo"

Then the entry should be

foo soft nofile 9000

foo hard nofile 65000




If you want to set the nofile only for superuser you just write root instead of user.


root soft nofile 9000

root hard nofile 65000



Now after rebooting you can see in the terminal with ulimit -a the change.

Wednesday, September 21, 2011

How to disable the web administration console? http://localhost:8080/axis2/axis2-admin/

How to disable the web administration console? http://localhost:8080/axis2/axis2-admin/

Environment:
Axis2-1.6.0

This is a common problem that many users asks and most of them thinks
that this can be done by changing a property in axis2.xml file.

There are more than one way to carry out this task. First we need to
say that axis2.xml has no control on disabling this admin console.
Because of that, changing the properties of axis2.xml file will not
effect on this requirement.

Here i ll specify two different ways to fulfill your requirement.
Both of them will prevent accessing the JSP file which is required to
load the Web Admin Console.

01: Changing the web.xml file

You can find this file at : webapps/axis2/WEB-INF folder.
In this file , you will find the following entry

<servlet-mapping>
<servlet-name>AxisAdminServlet</servlet-name>
<url-pattern>/axis2-admin/*</url-pattern>
</servlet-mapping>

You can comment this entry like

<!--servlet-mapping>
<servlet-name>AxisAdminServlet</servlet-name>
<url-pattern>/axis2-admin/*</url-pattern>
</servlet-mapping-->


This will prevent the page redirection and it will solve your problem.

02: Renaming or Deleting the Login.jsp file

You can find this file at : webapps/axis2/axis2-web folder.
you can delete or rename this file to any other name.
This will prevent access to Login page and it will solve your problem.

Friday, August 5, 2011

Hector Client Exception : InvalidRequestException(why:Expected 8 or 0 byte long (9))

We are getting the following kind of exception due to a small mistake that we do in creating column families in cassandra. I had created the column family with providing
comparator type as LONG.

But once i try to insert columns having String values as column names it throws this error.

Solution: Drop the created column family using cassandra-cli
create the Column Family with appropriate comparator type


me.prettyprint.hector.api.exceptions.HInvalidRequestException: InvalidRequestException(why:Expected 8 or 0 byte long (9))
at me.prettyprint.cassandra.service.ExceptionsTranslatorImpl.translate(ExceptionsTranslatorImpl.java:42)
at me.prettyprint.cassandra.service.KeyspaceServiceImpl$1.execute(KeyspaceServiceImpl.java:95)
at me.prettyprint.cassandra.service.KeyspaceServiceImpl$1.execute(KeyspaceServiceImpl.java:88)
at me.prettyprint.cassandra.service.Operation.executeAndSetResult(Operation.java:101)
at me.prettyprint.cassandra.connection.HConnectionManager.operateWithFailover(HConnectionManager.java:156)
at me.prettyprint.cassandra.service.KeyspaceServiceImpl.operateWithFailover(KeyspaceServiceImpl.java:129)
at me.prettyprint.cassandra.service.KeyspaceServiceImpl.batchMutate(KeyspaceServiceImpl.java:100)
at me.prettyprint.cassandra.service.KeyspaceServiceImpl.batchMutate(KeyspaceServiceImpl.java:106)
at me.prettyprint.cassandra.model.MutatorImpl$2.doInKeyspace(MutatorImpl.java:172)
at me.prettyprint.cassandra.model.MutatorImpl$2.doInKeyspace(MutatorImpl.java:169)
at me.prettyprint.cassandra.model.KeyspaceOperationCallback.doInKeyspaceAndMeasure(KeyspaceOperationCallback.java:20)
at me.prettyprint.cassandra.model.ExecutingKeyspace.doExecute(ExecutingKeyspace.java:72)
at me.prettyprint.cassandra.model.MutatorImpl.execute(MutatorImpl.java:169)
at org.apache.qpid.server.store.CassandraMessageStore.addMessageContent(CassandraMessageStore.java:267)
at org.apache.qpid.server.store.CassandraMessageStore$StoredCassandraMessage.addContent(CassandraMessageStore.java:620)
at org.apache.qpid.server.queue.IncomingMessage.addContentBodyFrame(IncomingMessage.java:144)
at org.apache.qpid.server.AMQChannel.publishContentBody(AMQChannel.java:391)
at org.apache.qpid.server.protocol.AMQProtocolEngine.contentBodyReceived(AMQProtocolEngine.java:477)
at org.apache.qpid.framing.ContentBody.handle(ContentBody.java:83)
at org.apache.qpid.server.protocol.AMQProtocolEngine.frameReceived(AMQProtocolEngine.java:336)
at org.apache.qpid.server.protocol.AMQProtocolEngine.dataBlockReceived(AMQProtocolEngine.java:285)
at org.apache.qpid.server.protocol.AMQProtocolEngine$1.run(AMQProtocolEngine.java:256)
at org.apache.qpid.pool.Job.processAll(Job.java:110)
at org.apache.qpid.pool.Job.run(Job.java:149)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: InvalidRequestException(why:Expected 8 or 0 byte long (9))
at org.apache.cassandra.thrift.Cassandra$batch_mutate_result.read(Cassandra.java:16477)
at org.apache.cassandra.thrift.Cassandra$Client.recv_batch_mutate(Cassandra.java:916)
at org.apache.cassandra.thrift.Cassandra$Client.batch_mutate(Cassandra.java:890)
at me.prettyprint.cassandra.service.KeyspaceServiceImpl$1.execute(KeyspaceServiceImpl.java:93)
... 25 more