Return-Path: X-Original-To: apmail-activemq-users-archive@www.apache.org Delivered-To: apmail-activemq-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id AA96510189 for ; Tue, 16 Jul 2013 20:07:14 +0000 (UTC) Received: (qmail 5751 invoked by uid 500); 16 Jul 2013 20:07:14 -0000 Delivered-To: apmail-activemq-users-archive@activemq.apache.org Received: (qmail 5702 invoked by uid 500); 16 Jul 2013 20:07:14 -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 5694 invoked by uid 99); 16 Jul 2013 20:07:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Jul 2013 20:07:13 +0000 X-ASF-Spam-Status: No, hits=2.5 required=5.0 tests=FREEMAIL_REPLY,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of christian.posta@gmail.com designates 209.85.215.51 as permitted sender) Received: from [209.85.215.51] (HELO mail-la0-f51.google.com) (209.85.215.51) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Jul 2013 20:07:09 +0000 Received: by mail-la0-f51.google.com with SMTP id fq12so889433lab.10 for ; Tue, 16 Jul 2013 13:06:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=MXp3uOdQCd/dEwYF7Pihr1cow0MpPlnq+enTXo5f35A=; b=WMurFOFot8+pVdC4BdrrWREQKGQFQcEzZvBgXB9B4mJqBmTZQmOz0O9BcTO757hn5p tXioM3G1UUlIybbbhriJt2W8WLsmjWjYB9fm77QQhviNXNAGtT8CcKvd8wrq+XuEDeiU ppd3PIpfCZh0QITeNkNtCFwA2iEjRBig7dVTmNn1mTKYdwuyDXIpWWv2hWFdMJXIuB1B B6VKLCWwMGKGsikfMYn5fqOGeJl1nIFs8oDCkfX4ouVaaLpIKiifYPCl0e+SwvgHQA98 cchYSDvm+nOTd06AeuZQddzpJxJ//vtIaowpimc9TxCPiqXFiGACFWCdU8Xn0HEnWXG/ eDGA== MIME-Version: 1.0 X-Received: by 10.152.25.135 with SMTP id c7mr1456464lag.39.1374005207442; Tue, 16 Jul 2013 13:06:47 -0700 (PDT) Received: by 10.114.185.37 with HTTP; Tue, 16 Jul 2013 13:06:47 -0700 (PDT) In-Reply-To: References: Date: Tue, 16 Jul 2013 16:06:47 -0400 Message-ID: Subject: Re: trying to consume (remove) a message From: Christian Posta To: "users@activemq.apache.org" Content-Type: multipart/alternative; boundary=089e0160c4064f286b04e1a6848d X-Virus-Checked: Checked by ClamAV on apache.org --089e0160c4064f286b04e1a6848d Content-Type: text/plain; charset=ISO-8859-1 Trunk. What version is in tomEE 1.5.2? On Tue, Jul 16, 2013 at 3:56 PM, Leonardo K. Shikida wrote: > I am using activemq from tomEE 1.5.2 > > probably not the latest > > what version are you using? > > [] > > Leo > > > On Tue, Jul 16, 2013 at 4:51 PM, Christian Posta > wrote: > > This unit test works: > > > > > > @Test > > public void remove() throws JMSException, InterruptedException { > > > > boolean messageConsumed = false; > > > > Connection connection = null; > > Session session = null; > > try { > > ConnectionFactory connectionFactory = new > > ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); > > connection = connectionFactory.createConnection(); > > connection.start(); > > > > session = connection.createSession(false, > > Session.AUTO_ACKNOWLEDGE); > > Queue queue = session.createQueue("FOO"); > > MessageProducer producer = session.createProducer(queue); > > for (int i = 0; i < 5; i++) { > > producer.send(session.createTextMessage("Hi" + i)); > > } > > > > > > QueueBrowser browser = session.createBrowser(queue); > > Enumeration messagesInQueue = browser.getEnumeration(); > > String jmsMessageID = "nan"; > > while (messagesInQueue.hasMoreElements()) { > > Message queueMessage = (Message) > > messagesInQueue.nextElement(); > > System.out.println("Enqueued > " + > > queueMessage.getJMSMessageID()); > > jmsMessageID = queueMessage.getJMSMessageID(); > > > > } > > > > System.out.println("Trying to delete > " + jmsMessageID); > > > > > > MessageConsumer consumer = > > session.createConsumer(queue, "JMSMessageID='" + > > jmsMessageID + "'"); > > Message message = null; > > while ((message = consumer.receive(500)) != null) { > > System.out.println("Consumed > " + message); > > } > > > > } finally { > > if (session != null) > > session.close(); > > if (connection != null) > > connection.close(); > > } > > > > } > > > > > > On Tue, Jul 16, 2013 at 3:41 PM, Leonardo K. Shikida >wrote: > > > >> Hi > >> > >> I've tried > >> > >> consumer.receive(1000) > >> > >> without success > >> > >> [] > >> > >> Leo > >> > >> > >> On Tue, Jul 16, 2013 at 4:25 PM, Christian Posta > >> wrote: > >> > Try giving a brief moment between creating your consumers and the > call to > >> > receiveNoWait(): > >> > > >> > MessageConsumer consumer = > >> > session.createConsumer(queue, "JMSMessageID='" + > >> > jmsMessageID + "'"); > >> > Message message = null; > >> > Thread.sleep(500); > >> > while ((message = consumer.receiveNoWait()) != null) { > >> > System.out.println("Consumed > " + message); > >> > } > >> > > >> > Alternatively, use consumer.receive(500) > >> > > >> > > >> > On Tue, Jul 16, 2013 at 11:10 AM, Leonardo K. Shikida < > shikida@gmail.com > >> >wrote: > >> > > >> >> Hi > >> >> > >> >> I am trying to remove (consume) a message from the queue, without > >> success. > >> >> > >> >> Here's my code and the output > >> >> > >> >> public boolean remove(String jmsMessageID) throws JMSException{ > >> >> > >> >> boolean messageConsumed = false; > >> >> > >> >> Connection connection = null; > >> >> Session session = null; > >> >> try { > >> >> ConnectionFactory connectionFactory = > >> >> this.baseService.getConnectionFactory(); > >> >> connection = connectionFactory.createConnection(); > >> >> connection.start(); > >> >> > >> >> // Create a Session > >> >> session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); > >> >> > >> >> QueueBrowser browser = > >> session.createBrowser(this.baseService.getQueue()); > >> >> Enumeration messagesInQueue = browser.getEnumeration(); > >> >> > >> >> while (messagesInQueue.hasMoreElements()) { > >> >> Message queueMessage = (Message) messagesInQueue.nextElement(); > >> >> System.out.println("Enqueued > "+queueMessage.getJMSMessageID()); > >> >> } > >> >> > >> >> System.out.println("Trying to delete > "+jmsMessageID); > >> >> > >> >> Queue queue = this.baseService.getQueue(); > >> >> MessageConsumer consumer = > >> >> session.createConsumer(queue,"JMSMessageID='"+jmsMessageID+"'"); > >> >> Message message = null; > >> >> while((message = consumer.receiveNoWait()) != null){ > >> >> System.out.println("Consumed > "+message); > >> >> messageConsumed = true; > >> >> } > >> >> > >> >> } finally { > >> >> if (session != null) > >> >> session.close(); > >> >> if (connection != null) > >> >> connection.close(); > >> >> } > >> >> > >> >> return messageConsumed; > >> >> } > >> >> > >> >> >>>>>>> > >> >> > >> >> Enqueued > > >> >> ID:7612866413.mydomain.com-58510-1373986917055-5:1:35:1:1 > >> >> Enqueued > > >> >> ID:7612866413.mydomain.com-58510-1373986917055-5:1:61:1:1 > >> >> Enqueued > > >> >> ID:7612866413.mydomain.com-58510-1373986917055-5:1:63:1:1 > >> >> Trying to delete > > >> >> ID:7612866413.mydomain.com-58510-1373986917055-5:1:63:1:1 > >> >> > >> >> (never enter into System.out.println("Consumed > "+message);) > >> >> > >> >> Am I missing something here? > >> >> > >> >> [] > >> >> > >> >> Leo > >> >> > >> > > >> > > >> > > >> > -- > >> > *Christian Posta* > >> > http://www.christianposta.com/blog > >> > twitter: @christianposta > >> > > > > > > > > -- > > *Christian Posta* > > http://www.christianposta.com/blog > > twitter: @christianposta > -- *Christian Posta* http://www.christianposta.com/blog twitter: @christianposta --089e0160c4064f286b04e1a6848d--