Return-Path: Delivered-To: apmail-activemq-users-archive@www.apache.org Received: (qmail 88365 invoked from network); 3 Sep 2008 13:11:01 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Sep 2008 13:11:01 -0000 Received: (qmail 1419 invoked by uid 500); 3 Sep 2008 13:10:58 -0000 Delivered-To: apmail-activemq-users-archive@activemq.apache.org Received: (qmail 1404 invoked by uid 500); 3 Sep 2008 13:10:58 -0000 Mailing-List: contact users-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@activemq.apache.org Delivered-To: mailing list users@activemq.apache.org Received: (qmail 1393 invoked by uid 99); 3 Sep 2008 13:10:58 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 03 Sep 2008 06:10:58 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of james.strachan@gmail.com designates 64.233.184.225 as permitted sender) Received: from [64.233.184.225] (HELO wr-out-0506.google.com) (64.233.184.225) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 03 Sep 2008 13:09:59 +0000 Received: by wr-out-0506.google.com with SMTP id 50so2432485wri.2 for ; Wed, 03 Sep 2008 06:10:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=GrAkYO98J+PMar2DL0Kv1/BeEvRLZTBqh7O6iB0c1BU=; b=A9PBpqDG4sHoG3TlULYhmOdqzrffBewQPl06hptf/DsjTzoIT5LY7KCNfAqStHiEta aIyyj1/HafpzzKsRlgIF6rxC7jyXKYscBDjUh3bbLk6nI9jQ8UCS6n/8NPPsA/LAEcZ4 0Ogse/R2x7nklurZZfTFXzlmRxbmOngFrT4sQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=gUnvBe2AokAZbM7ca1jfdZyp1CRrk35sLyIYHvSPTNzZJbxt0kQIEjGcc2qBblSjQh SKLXxlv4iREW9tY6ldFLScwRjbe5lZirAPAl/J+PXwoJF3Y0rCOrVrsX0vanrYFcnhUg RmTIXr+y5tfnOEnHsYT6R9jhqPbwiXzfxz9oI= Received: by 10.90.80.19 with SMTP id d19mr11295898agb.73.1220447412318; Wed, 03 Sep 2008 06:10:12 -0700 (PDT) Received: by 10.90.117.12 with HTTP; Wed, 3 Sep 2008 06:10:12 -0700 (PDT) Message-ID: Date: Wed, 3 Sep 2008 14:10:12 +0100 From: "James Strachan" To: users@activemq.apache.org Subject: Re: onMessage method of MessageListener is never called? In-Reply-To: <20080903130201.GA17506@office.redwerk.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20080903130201.GA17506@office.redwerk.com> X-Virus-Checked: Checked by ClamAV on apache.org If I had a dollar for every time someone's stumbled on this one in JMS... http://activemq.apache.org/i-am-not-receiving-any-messages-what-is-wrong.html 2008/9/3 Eugeny N Dzhurinsky : > Hello! > > 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 > queues? > > 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; > > @BeforeClass > public static void beforeClass() throws Exception { > factory = new ActiveMQConnectionFactory(CONNECTION_URL); > BasicConfigurator.configure(); > Logger.getRootLogger().setLevel(Level.DEBUG); > } > > @Test > public void testClientServerCommunication() throws Exception { > ConnectionFactory connectionFactory = new ActiveMQConnectionFactory( > CONNECTION_URL); > final ActiveMQConnection connection = (ActiveMQConnection) connectionFactory > .createConnection(); > > // 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 > .createQueue(IMAGES_SERVER_QUEUE); > final Destination clientQueue4Server = serverSession > .createQueue(IMAGES_CLIENT_QUEUE); > > // client queues > final Destination serverQueue4Client = clientSession > .createQueue(IMAGES_SERVER_QUEUE); > final Destination clientQueue = clientSession > .createQueue(IMAGES_CLIENT_QUEUE); > > // create producers > System.out.println("Create producers"); > final MessageProducer clientProducer = clientSession > .createProducer(serverQueue4Client); > clientProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); > > final MessageProducer serverProducer = serverSession > .createProducer(clientQueue4Server); > serverProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); > > Mockery mockery = new Mockery(); > final MessageListener listener = mockery.mock(MessageListener.class); > > mockery.checking(new Expectations() { > { > exactly(2).of(listener).onMessage(with(any(Message.class))); > } > }); > > // 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(); > request.setJMSMessageID("REQUEST"); > clientProducer.send(request); > > Message response = serverSession.createMessage(); > response.setJMSMessageID("RESPONSE"); > serverProducer.send(response); > > Thread.sleep(5 * 1000); > mockery.assertIsSatisfied(); > } > > @AfterClass > public static void afterClass() throws Exception { > } > > } > > Thank you in advance! > -- > Eugene N Dzhurinsky > -- James ------- http://macstrac.blogspot.com/ Open Source Integration http://open.iona.com