March 8 2017

Subscribing to a message from an Oracle AQ queue is not out of the box functionality within Mule, but can be done by following the steps provided in this article.

JMS transport

The first step to get a Mule flow to communicate with AQ is to add the following spring bean configuration:

<spring:beans> 
   <spring:bean id="connFactory" class="oracle.jms.AQjmsFactory" factory-method="getQueueConnectionFactory"> 
   <!-- JDBC URL -->   
      <spring:constructor-arg index="0"> 
         <spring:value>oracle db url</spring:value> 
      </spring:constructor-arg> 
   <!-- properties --> 
   <spring:constructor-arg index="1" type="java.util.Properties" value=""> 
   </spring:constructor-arg> 
   </spring:bean> 
</spring:beans>

As you probably noticed, a reference to the class, oracle.jms.AQjmsFactory is specified. This class which is found in the aqapi.jar provides the ability for Mule to utilize the JMS transport for communication with AQ. Another dependency to be added to the Mule project is the jmscommon.jar (these jars can be found within an Oracle install, such as SOA).

With the spring bean configuration set, reference it within the JMS connector attribute, ‘connectionFactory-ref’:

<jms:connector name="OracleAQConnector" 
   connectionFactory-ref="connFactory" 
   specification="1.1" 
   username="username" 
   password="password" 
   maxRedelivery="3" 
   doc:name="JMS" 
   numberOfConsumers="1" 
   validateConnections="true"> 
   <reconnect-forever frequency="2000" /> 
</jms:connector>

Now you can define your flow to subscribe to the queue using the AQ configuration:

<jms:inbound-endpoint queue="AQ_Name" connector-ref="OracleAQConnector" doc:name="JMS" />

 

Advanced Data Types

Once the JMS configuration is done, running the application may give you a result that is not expected, an error: Payload factory must be specified for destinations with ADT payloads.

If this is the case, you will need to add some Java code to your Mule application to enable the consumption of advanced data types (ADT). An ADT can be used to define the payload that is placed onto AQ within the Oracle database. This type is much like an object, but in Oracle-speak.

ORADataFactory Implementation

The first Java class to be written implements the ORADataFactory interface, which is used to describe the Oracle data types. Within this class, define the getters and setters for the ADT. This blog post provides an excellent example of how this is done.

Custom Message Receiver

With the ORADataFactory implemented, it now can be referenced by the next piece of the ADT puzzle. Create a Java class that overrides the default JMS message receiver (org.mule.transport.jms.JmsMessageReceiver or org.mule.transport.jms.MultiConsumerJmsMessageReceiver) and specify this new message receiver class in the JMS connector configuration:

<service-overrides messageReceiver="com.avio.jms.connectorOverride.CustomMessageReceiver" />

Within this class, reference the ORADataFactory class implemented within the createConsumer method:

   this.consumer = ((AQjmsSession)session).createConsumer(dest, selector,  
                     this.currentOraDataFactory, 
                    null, this.connector.isNoLocal());

Custom Transformer

The last step is to create a custom transformer which will transform the ADT into a POJO, allowing the message to be consumed by Mule. The code snippet below is an example of setting values in the POJO from the ADT fields within a custom transformer class:

    AQjmsAdtMessage aqPayload = (AQjmsAdtMessage)message.getPayload();   
    myPOJO qType = new myPOJO();   
    try {   
       AQCustomPayloadObject custPayload = (AQCustomPayloadObject)aqPayload.getAdtPayload();   
       qType.setValue(custPayload.getADTField);

Reference this new transformer within the JMS inbound endpoint:

<custom-transformer name="QtypeToPOJO" class="com.avio.CustomTransformer" doc:name="Java"/>

 

About the Author

Bio

Jennie has over 25 years of information technology experience, the majority of time spent in application integration. She has broad experience in integration architecture design and implementation utilizing several integration toolsets. As an architect, she has experience developing SOA/API Governance Framework and Reference Architectures.

Join the Conversation

Whatsapp Apk
March 30, 2017

Download WhatsApp apk on your device and introduced on the customary telephone and cell phone like the BlackBerry, Nokia, iPhone, Samsung or some other Android, Windows or Ubuntu telephone.

Enter your first name. It will only be used to display with your comment.
Enter your email. This will be used to validate you as a real user but will NOT be displayed with the comment.
By submitting this form, you accept the Mollom privacy policy.