Thursday, November 3, 2016

MySQL crashing on EC2 Micro Linux instance

Amazon Web Services (AWS) is great place to start playing / learning cloud technologies. AWS offers EC2 micro instances free of cost. This allows developers (like me) to try out various things, which in real corporate life very hard to do.

Last week I was playing with my EC2 micro instance. I installed Apache, MySQL and WordPress. I configured everything according to great tutorial published on AWS. Everything was great, working fine. But then I encountered an issue, my blog was failing more than couple of times a day. 

Problem:
On digging I found out that the MySQL daemon was failing due to insufficient memory. 

Details:
EC2 micro instance provides you with 1 vCPU and 1 GB of memory. Clearly this is not ideal for big application. But I am just creating a person blog site with only I am being the user :), so this should be sufficient. 
Problem lies with default setup of Linux, Apache and MySQL. Apache and MySQL tries to hog resources and with default Linux setup there is no swap memory allocated.

Solution:
After doing few hours of googling I arrived at following solutions (which worked for me)

1. Allocate swap 
  • Run dd if=/dev/zero of=/swapfile bs=1M count=1024
  • Run mkswap /swapfile
  • Run swapon /swapfile
  • Add this line /swapfile swap swap defaults 0 0 to /etc/fstab 
You might have to run above commands using sudo access. (Credit: http://www.prowebdev.us/2012/05/amazon-ec2-linux-micro-swap-space.html)

2. Reduce MySQL buffer pool size
Add following to /etc/my.cnf
[mysqld]

innodb_buffer_pool_size=64M

Then restart the MySQL and Apache. This should fix the issue of MySQL crashing on EC2 Micro Instance.

Thursday, October 29, 2015

Oracle Advanced Queue and Apache Camel Integration



Oracle Advanced Queueing (AQ) is the Oracle database's queue management feature. AQ provides a message queuing infrastructure as integral part of the Oracle server engine. It provides an API for enqueing messages to database queues. These messages can later be dequeued for asynchronous processing.

In short Oracle AQ  provides most of the functionalities which standard Message Queue (MQ) like ActiveMQ, RabbitMQ, etc. provides. But Oracle AQ is not widely used as MQ infrastructure and not very straight forward to integrate (at least I found very less documentation).

In this blog post I am explaining the basic steps to integrate Oracle AQ with Apache Camel, popular routing and mediation framework which implements Enterprise Integration Patterns. I am using Camel version 2.15.2, Spring 4.2.0 RELEASE with JDK 7. I am assuming you are aware of basics of Spring Camel integration and usage of Camel JMS component.


Below is how my camel-context.xml looks like

xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:context="http://www.springframework.org/schema/context"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd      http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
   

   <camelContext id="camelContext" errorHandlerRef="defaultErrorHandler" xmlns="http://camel.apache.org/schema/spring" >
      <package>com.abc.xyz.route</package>

   </camelContext>
   
   <bean id="connectionFactoryOracleAQQueue" class="oracle.jms.AQjmsFactory" factory-method="getQueueConnectionFactory">
      <constructor-arg index="0">
         <value>jdbc:oracle:thin:@(DESCRIPTION= (ADDRESS= (PROTOCOL=TCP) (HOST=host.org.com) (PORT=1521)) (CONNECT_DATA=  (SID=test)))</value>
      </constructor-arg>
      <constructor-arg index="1" type="java.util.Properties">
         <value></value>
      </constructor-arg>
   </bean>

   <bean id="oracleQueueCredentials" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
      <property name="targetConnectionFactory">
         <ref bean="connectionFactoryOracleAQQueue" />
      </property>
      <property name="username">
         <value>test</value>
      </property>
      <property name="password">
         <value>test</value>
      </property>
   </bean>

   <bean id="oracleQueue" class="org.apache.camel.component.jms.JmsComponent">
      <property name="connectionFactory" ref="oracleQueueCredentials" />
   </bean>
   
</beans>
 

And this is how my route looks like 

from("oracleQueue:TEST_Q")
        .routeId("AQSample")
        .log(LoggingLevel.INFO, "Processing message: ${body}")
        .processRef("myProcessor")
        .end();  

This looks simple enough... right? But when I tried to run this I started to get a lot of issue. The most prominent was 

DefaultMessageListenerContainer-1  
  java.lang.AbstractMethodError: oracle.jms.AQjmsQueueConnectionFactory.createConnection(Ljava/lang/String;Ljava/lang/String;)Ljavax/jms/Connection; 

Finally I got around this issue by adding proper version of aqapi13.jar and ojdbc14.jar. The correct version of these jars is normally not available in common maven repos (mostly because of license issue). Trick is to get these jars from Oracle installation you are trying to connect and add to local maven repo you are using.

There you go....

Tuesday, February 22, 2011

Apache Camel

It is a long time since I wrote my last blog. For last 6-7 months I am working on Apache Camel framework. This framework has amazing integration features. Very easy to learn and very good implementations of EIP (Enterprise Integration Patterns).
Camel lets you work easily with any kind of (well almost) trasport or messaging model such as HTTP, JMS, etc. It provides you 2 ways to write your routing / mediation rules
1. DSL (Domain Specific Language)
2. XML configuration (Spring based)
Couple of more features which blew me out were seamless Spring integration and amazing JUnit support to unit test your routes.
One more good thing is that Camel provides a framework by which one can develop a Camel component very easily. Component is way by which Camel integrates with other frameworks and systems.
By the way I am planning to write a Camel Component and donate to Apache. Will let you know about it my next blog.

Sunday, March 22, 2009

Integration of JSF and Spring

JSF is a very popular presentation framework for web applications. It has got very rich repository of components as well. Spring help structuring whole application in a consistent, productive manner, pulling together best-of-breed frameworks. Spring enable developers to work with POJOs. Spring is a lightweight container, providing centralized, automated configuration and wiring of application objects.
So JSF in web tier and Spring in middle tier become an obvious choice. This document explains the steps involved in integrating these two frameworks.

Steps involved in integration
1. Add following lines in web.xml


This will load Spring Application context when web application starts.

2. Add applicationContext.xml file in WEB-INF folder
applicationContext.xml is a Spring configuration file. In the below snippet shows JSF managed bean entry.



3. Add following lines to faces-config.xml


When the code sample above is executed then the DelegatingVariableResolver would check to see if "SampleView" exists in spring and if it exists as a JSF managed bean as well. If it does DelegatingVariableResolver will then check to see if the bean already exists in the scope specified by and returns that instance if it exists. Otherwise, VariableResolver creates a new bean (SampleView), performs the JSF wiring on any managed properties on top of the already wired spring bean, stores the bean in the scope specified, and returns it.

Above is one of the ways of integrating JSF and Spring. With this approach advantages of both the frameworks can be achieved. Using this approach one can also integrate Faces Portlets with Spring based business tier.

Thursday, February 26, 2009

TIBCO General Interfaces (GI)


Now a day everybody talks about building internet applications using Rich User Interface. It makes sense also as Rich User Interface gives Rich User Experience. There are lots of frameworks in the market for building Rich Internet Application like Flex, Bindows, GI etc. In this article we will take a look at TIBCO General Interfaces.

TIBCO GI is a cool tool to develop Rich Internet Applications (RIA). TIBCO GI is based on Ajax technology. It has got a set what TIBCO calls ‘Lean Javascript’ libraries. GI Framework has got rich set of UI components and provides all the features that a typical web framework has like MVC, data binding, caching, localization, logging and debugging. Following are the some highlights about TIBCO GI.

IDE
The worst problem with typical RIA frameworks is unavailability of IDE. Because of this developer has to hand code everything, which obviously brings the productivity down. With GI this problem is not there. It has got amazing IDE (General Interface Builder), which is built on the same framework. GI Builder IDE looks very similar to VB with drag-drop features, enabling developer to build UI very quickly and easily. This IDE is packed with some cool tools like one can debug Javascript which is otherwise very difficult. It has got Error Console which lists Javascript errors which IDE has detected. Also it does not need any installer, it runs in a browser!!

Javascript Based
GI is completely based on Javascript which loads and runs in end user’s browsers. All UI components have events, on which Javascript functions can be called.

API Documentation
GI has got very well structured API documentation just like Java. One can find this in help section of the IDE.

Webservice Mapping
This is another feature which I liked the most. You can expose your business logic as Webservice and GI allows you to map input and output parameters with UI components, that tool having drag-drop features.

Integration
GI integrates well with major J2EE frameworks like Struts, Spring etc.


Browser Compatibility
GI supports all major browsers like IE, Firefox, etc. This enables developer to focus on business rather than focusing on browser specific coding.

Rich Component Library
GI has got very good component library which you can just drag-drop and start building the application. It has got very rich set of components like various grids, charting components, etc.

And above all, TIBCO GI is ‘Open Source’.

Interested…. Want to try out some stuff using GI… Refer following links

TIBCO GI Home : http://gi.tibco.com/
TIBCO GI Resource Center: http://www.tibco.com/devnet/gi/
TIBCO GI with Spring: http://www.theserverside.com/tt/articles/article.tss?l=AjaxandSpring