Showing posts with label Apache Camel. Show all posts
Showing posts with label Apache Camel. Show all posts

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.