From users-return-50574-archive-asf-public=cust-asf.ponee.io@activemq.apache.org Sun Oct 14 05:25:45 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id A9899180638 for ; Sun, 14 Oct 2018 05:25:44 +0200 (CEST) Received: (qmail 11293 invoked by uid 500); 14 Oct 2018 03:25:38 -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 11281 invoked by uid 99); 14 Oct 2018 03:25:37 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 14 Oct 2018 03:25:37 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id E4AF81A077D for ; Sun, 14 Oct 2018 03:25:36 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.551 X-Spam-Level: ** X-Spam-Status: No, score=2.551 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_NEUTRAL=0.652] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (1024-bit key) header.d=servicefriend.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id c6tV1UEKuI6G for ; Sun, 14 Oct 2018 03:25:35 +0000 (UTC) Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id D2ED35F11D for ; Sun, 14 Oct 2018 03:25:34 +0000 (UTC) Received: by mail-lf1-f41.google.com with SMTP id p34-v6so11810366lfg.10 for ; Sat, 13 Oct 2018 20:25:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=servicefriend.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=7BqQOab8aLLotsD1EghPv95fRNHHatw32LbbjmRHoUk=; b=OzB11fIN+nSN3fYuH4JLW++UWhlL2LX7i3hqNZ4HmELpxGVFRVejs9hswfbkw9hoxz egfQBpuNNr9Q//Qsh0Yv1QN5fga368/TKd47Lugdcv14G+eTpkBr7Ms0flHaGvVqtdBg P24ss4mrWbfrLYdQjqo/6R/axC3u9kIK0pSdQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=7BqQOab8aLLotsD1EghPv95fRNHHatw32LbbjmRHoUk=; b=DVEZYGvtBNDk9xxzDagCe/PjhBh7sCo5VEbJGzszdCIlVD1CB50VprV3GdRAwW5uAE GQy7k+ozI5rsPcOASWE+7EkjP6TpT8W9en24UdSY+YirnXU2FmvpyBGD75fDZcYIKcd9 NQ7nvRccmJvzA7W8VyOAQAHXOwsiW+AW9vtW0G7cpiEUj5Vi4hFVo3PgcClm1gMay0df M19vbigUv9v+ubJiV2YMRAR3QipA6AZJEtD7R/RSvXUmpSGlU5ne0XZEF0Ep7XneD1LB CfVQYNYG54iCSRqujXe5C19H2pX3Ox9g3LRadvdwrjxDhxYKDSzAiW93rQbqrMqDyLXl pJvg== X-Gm-Message-State: ABuFfoitnI0lkh+qPVFw4DNx97zSXiis2y45NRb/xLlWuEDO7aPCe+x2 WKvRg7WhWNsXv1xGdcOAUVGitjUSU0LBPi/2tYbUdVT6lxL1qA== X-Google-Smtp-Source: ACcGV61ajuGU41j72iWkzHdr5doPQbloe0vHiYH238qhq7Uqdu/8yAK/7CiAU6DuEmUkfLiTLcOHW3BOEugo/0GQN2o= X-Received: by 2002:a19:a2c1:: with SMTP id l184-v6mr7299116lfe.33.1539487533203; Sat, 13 Oct 2018 20:25:33 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Moshe Recanati Date: Sun, 14 Oct 2018 06:25:21 +0300 Message-ID: Subject: Re: Using ActiveMQ with more than one consumer instance To: users@activemq.apache.org Content-Type: multipart/alternative; boundary="0000000000008d9aea057827dfe4" --0000000000008d9aea057827dfe4 Content-Type: text/plain; charset="UTF-8" Hi Tim, Thank you see my code below. Keep in mind that I do want that message will be available until it processed successfully. // Establish a connection for the consumer. final Connection consumerConnection = connectionFactory.createConnection(); consumerConnection.start(); // Create a session. final Session consumerSession = consumerConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE); final Destination consumerDestination = consumerSession.createQueue(queueName); *public void recieveMessages(String queueName) throws Exception {* *// Create a message consumer from the session to the queue.final MessageConsumer consumer = consumerSession.createConsumer(consumerDestination);// Begin to wait for messages.Queue queue = consumerSession.createQueue(queueName);QueueBrowser queueBrowser = consumerSession.createBrowser(queue);Enumeration msgs = queueBrowser.getEnumeration();while (msgs.hasMoreElements()) { //do your things here ActiveMQTextMessage message = (ActiveMQTextMessage) msgs.nextElement(); if (message == null) continue; //handle message System.out.println("Message received in : " + message); try { String text = message.getText(); JSONObject messageJson = new JSONObject(text); consumer.receive(1000); String responseString = handleMessage(messageJson); message.acknowledge();* *.....* Moshe On Sun, Oct 14, 2018 at 5:52 AM Tim Bain wrote: > The behavior you want is the default behavior for a queue, so if you're > seeing the behavior you describe, it probably means you're doing something > wrong with the code that's acknowledging the message. (That, or you're > using a topic, not a queue.) Can you post the code that acknowledges the > message? > > Alternatively, can you use AUTO_ACK mode instead of CLIENT_ACK mode, to > eliminate any errors relating to your acknowledgement code? > > Tim > > On Sat, Oct 13, 2018, 1:33 PM Moshe Recanati < > moshe.recanati@servicefriend.com> wrote: > > > Hi, > > In our architecture we've 2 or more containers for each application for > > high availiability puproses. > > We're using activeMQ and I would like to implement the following > behavior. > > > > 1. Pushing to a message to queue. > > 2. This message will be consumed only by *one *container (the first one > > that will read it). > > 2. Once message processed successfully the consumer will update this > > message can be acknowledged and neglected > > 3. I tried using transaction with commit and using CLIENT_ACKNOWLEDGE > > however > > in both cases both consumers got the message and processed it. > > > > I want only one consumer to process each message based on availability. > > > > Please share the way to implement it. > > > > Thank you > > Moshe > > > --0000000000008d9aea057827dfe4--