Alex Rudyy created QPIDJMS-264:
----------------------------------

             Summary: Incoming messages are dispatched out of order 
                 Key: QPIDJMS-264
                 URL: https://issues.apache.org/jira/browse/QPIDJMS-264
             Project: Qpid JMS
          Issue Type: Bug
          Components: qpid-jms-client
    Affects Versions: 0.20.0
            Reporter: Alex Rudyy
            Priority: Critical


Both current trunk version and version 0.20.0 of JMS Client can dispatch 
incoming messages out of order into client application. I did not test earlier 
versions. The messages are received in the right order but Client dispatches 
them occasionally out of order.

I used the following code to reproduce the issue with trunk version of Java 
Broker.

{code}
public static void main(String[] args) throws Exception
    {
        for (int i=0;i<100;i++)
        {
            execute(i);
        }
    }

    public static void execute(int iteration) throws Exception
    {
        System.out.println("Iteration " + iteration);

        Connection managingConnection = createConnection();
        Session session = 
managingConnection.createSession(Session.SESSION_TRANSACTED);

        Connection consumingConnection = createConnection();
        Session consumerSession = consumingConnection.createSession(true, 
Session.SESSION_TRANSACTED);

        Queue queue = createTestQueue(session, "Q3-test");
        session.commit();

        MessageConsumer consumer = consumerSession.createConsumer(queue);

        Connection producingConnection = createConnection();
        Session producerSession = producingConnection.createSession(true, 
Session.SESSION_TRANSACTED);
        MessageProducer producer = producerSession.createProducer(queue);

        producer.send(producerSession.createTextMessage("msg1"));
        producer.send(producerSession.createTextMessage("msg2"));
        producer.send(producerSession.createTextMessage("msg3"));
        producer.send(producerSession.createTextMessage("msg4"));

        producerSession.commit();

        consumingConnection.start();
        TextMessage tm = (TextMessage) consumer.receive();

        System.out.println(">" + tm.getText());
        if (!"msg1".equals(tm.getText()))
        {
            throw new RuntimeException("Unexpected");
        }

        deleteQueue(session, "Q3-test");
        consumingConnection.close();
        producingConnection.close();
        managingConnection.close();

    }

    private static Queue createTestQueue(Session session, String queueName) 
throws JMSException
    {
        MessageProducer producer = 
session.createProducer(session.createQueue("$management"));

        MapMessage createMessage = session.createMapMessage();
        createMessage.setStringProperty("type", "org.apache.qpid.Queue");
        createMessage.setStringProperty("operation", "CREATE");
        createMessage.setString("name", queueName);
        createMessage.setString("object-path", "org.apache.qpid.Queue");
        producer.send(createMessage);
        if (session.getTransacted())
        {
            session.commit();
        }
        return session.createQueue(queueName);
    }

    private  static void deleteQueue(Session session, String queueName)throws 
JMSException
    {
        MessageProducer producer = 
session.createProducer(session.createQueue("$management"));

        MapMessage createMessage = session.createMapMessage();
        createMessage.setStringProperty("type", "org.apache.qpid.Queue");
        createMessage.setStringProperty("operation", "DELETE");
        createMessage.setStringProperty("index", "object-path");

        createMessage.setStringProperty("key", queueName);
        producer.send(createMessage);
        if (session.getTransacted())
        {
            session.commit();
        }
    }

    private static Connection createConnection() throws JMSException, 
NamingException {
        Properties properties = new Properties();
        properties.put("java.naming.factory.initial", 
"org.apache.qpid.jms.jndi.JmsInitialContextFactory");
        properties.put("connectionfactory.myFactoryLookup", 
"amqp://localhost:5672");
        Context context = new InitialContext(properties);
        try
        {
            ConnectionFactory factory = (ConnectionFactory) 
context.lookup("myFactoryLookup");
            return factory.createConnection("admin", "admin");
        }
        finally
        {
            context.close();
        }
    }
{code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@qpid.apache.org
For additional commands, e-mail: dev-h...@qpid.apache.org

Reply via email to