Tuesday, July 26, 2011

Queue interchanges first and second element when use poll with browser

The issue I faced is, when i used QueueBrowser with  poll, Browser browsed elements in order but consumer started to remove from 2nd element. My scenario was simple,
First browser, then poll..

Our common Message Store implementation is written in a way to support all JMS providers ande code works fine with the most of the JMS providers(Qpid,ActiveMQ 5.3.XX) but didn't work with ActiveMQ 5.4.2/5.5 version..


public void peek() throws Exception {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost"); Connection connection = connectionFactory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
destination = (ActiveMQDestination) session.createQueue("TEST.FOO");
QueueBrowser browser = session.createBrowser((Queue) destination);

Enumeration enumeration = browser.getEnumeration();

if (enumeration.hasMoreElements()) {
Object msg = enumeration.nextElement();
TextMessage m = (TextMessage) msg;
System.out.println("Browsed msg " + m.getText());

}

browser.close();
session.close();
connection.close();

}

public void poll() throws Exception {

ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory( "vm://localhost");
Connection connection = connectionFactory.createConnection();
connection.start();

Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
destination = (ActiveMQDestination) session.createQueue("TEST.FOO");

MessageConsumer consumer = session.createConsumer(destination);

TextMessage m = (TextMessage) consumer.receive(1000);
if (m != null) {
System.out.println(" Polled Messg" + m.getText());
}

consumer.close();
session.close();
connection.close();
}


I tested with above test code and it works fine with ActiveMQ V5.4.2..Not only works in the application..
To overcome the issue, we did an extra iteration wherever we use the Queuebrowser and it solved the issue..


@ the peek() call we added iteration,


  if (enumeration.hasMoreElements()) {
   Object msg = enumeration.nextElement();
   TextMessage m = (TextMessage) msg;
             while(enumeration.hasMoreElements()){
                           enumeration.nextElement();
                        }

  }

Tuesday, July 19, 2011

Configuring WSO2ESB 4.0.0 with QPid

This is how we need to  configure ESB with Qpid,

1) Edit axis2.xml file(ESB_HOME/rpository/conf/axis2.xml) like;

Under transport In section;
<!--Transport Ins -->
<!--Uncomment this and configure as appropriate for JMS transport support with Apache Qpid -->

<transportReceiver name="jms" class="org.apache.axis2.transport.jms.
JMSListener">

 <parameter name="myTopicConnectionFactory" locked="false">
   <parameter name="java.naming.factory.initial" locked="false">
    org.apache.qpid.jndi.PropertiesFileInitialContextFactory</parameter> 
    repository/conf/jndi.properties</parameter>
   <parameter name="java.naming.provider.url" locked="false">
     repository/conf/jndi.properties</parameter>  
   <parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">
    TopicConnectionFactory</parameter>
   <parameter name="transport.jms.ConnectionFactoryType" locked="false">
    topic</parameter>
 </parameter>
 <parameter name="myQueueConnectionFactory" locked="false">
    <parameter name="java.naming.factory.initial" locked="false">
    org.apache.qpid.jndi.PropertiesFileInitialContextFactory</parameter>
    <parameter name="java.naming.provider.url" locked="false">
    repository/conf/jndi.properties</parameter>
    <parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">
    QueueConnectionFactory</parameter>
    <parameter name="transport.jms.ConnectionFactoryType" locked="false">
    queue</parameter>
  </parameter>

</transportReceiver>

Under Transport Outs section;


<transportSender name="jms" class="org.apache.axis2.transport.jms.JMSSender"/>

2) At jndi.properties file(ESB_HOME/repository/conf/jndi.properties);
Add following lines to create connectionfactory, queue , topic etc..

connectionfactory.TopicConnectionFactory = amqp://admin:admin@carbon/carbon?brokerlist='tcp://localhost:5672'
connectionfactory.QueueConnectionFactory = amqp://admin:admin@carbon/carbon?brokerlist='tcp://localhost:5672'
queue.MyQueue = example.MyQueue
queue.DLCStore = example.DLCStore


3) Your MessageStore configuartaion should have minimum three parameters;

<messageStore xmlns="http://ws.apache.org/ns/synapse" class="org.wso2.carbon.message.store.persistence.jms.JMSMessageStore" name="testMsgStore">
    <parameter name="java.naming.factory.initial">org.apache.qpid.jndi.PropertiesFileInitialContextFactory</parameter>
    <parameter name="java.naming.provider.url">repository/conf/jndi.properties</parameter>
    <parameter name="store.jms.destination">MyQueue</parameter>
</messageStore>



I have written a KB about configuring Qpid with WSO2 ESB,which has been published @ WSO2 OT..