activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eugeny N Dzhurinsky <>
Subject onMessage method of MessageListener is never called?
Date Wed, 03 Sep 2008 13:02:01 GMT

I am trying to write the test for my application which uses requests and
response queues for handling message processing. I recently realized the
onMessage is never being called on the MessageConsumer. I wrote the sample
code listed below and it is really true - onMessage is just skipped. However
in the logs of ActiveMQ I can see the messages are routed and dropped to

Can somebody please take a look at the sample unit test below and let me know
what did I miss?


import javax.jms.*;

import org.apache.activemq.*;
import org.apache.log4j.*;
import org.jmock.*;
import org.junit.*;

 * Client-server test case
public class TestClientServer {

    private static final String IMAGES_CLIENT_QUEUE = "images_client";

    private static final String IMAGES_SERVER_QUEUE = "images_server";

    private static final String CONNECTION_URL = "vm://localhost?broker.persistent=false";

    static ActiveMQConnectionFactory factory;

    public static void beforeClass() throws Exception {
        factory = new ActiveMQConnectionFactory(CONNECTION_URL);

    public void testClientServerCommunication() throws Exception {
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
        final ActiveMQConnection connection = (ActiveMQConnection) connectionFactory

        // create sessions
        System.out.println("Create sessions");
        final ActiveMQSession serverSession = (ActiveMQSession) connection
                .createSession(false, Session.AUTO_ACKNOWLEDGE);
        final ActiveMQSession clientSession = (ActiveMQSession) connection
                .createSession(false, Session.AUTO_ACKNOWLEDGE);

        // create queue
        System.out.println("Create destinations");
        // server queues
        final Destination serverQueue = serverSession
        final Destination clientQueue4Server = serverSession

        // client queues
        final Destination serverQueue4Client = clientSession
        final Destination clientQueue = clientSession

        // create producers
        System.out.println("Create producers");
        final MessageProducer clientProducer = clientSession

        final MessageProducer serverProducer = serverSession

        Mockery mockery = new Mockery();
        final MessageListener listener = mockery.mock(MessageListener.class);

        mockery.checking(new Expectations() {

        // create consumers
        System.out.println("Create consumers");
        final MessageConsumer clientConsumer = clientSession.createConsumer(
                clientQueue, listener);
        final MessageConsumer serverConsumer = serverSession.createConsumer(
                serverQueue, listener);

        Message request = clientSession.createMessage();

        Message response = serverSession.createMessage();

        Thread.sleep(5 * 1000);

    public static void afterClass() throws Exception {


Thank you in advance!
Eugene N Dzhurinsky

View raw message