Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id A420C200CE9 for ; Sat, 19 Aug 2017 15:18:00 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id A28A416505E; Sat, 19 Aug 2017 13:18:00 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id BCB5D16505D for ; Sat, 19 Aug 2017 15:17:59 +0200 (CEST) Received: (qmail 75366 invoked by uid 500); 19 Aug 2017 13:17: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 75353 invoked by uid 99); 19 Aug 2017 13:17:57 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 19 Aug 2017 13:17:57 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 6559CC0385 for ; Sat, 19 Aug 2017 13:17:57 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 5.043 X-Spam-Level: ***** X-Spam-Status: No, score=5.043 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, HEADER_FROM_DIFFERENT_DOMAINS=0.001, HTML_MESSAGE=2, KAM_LIVE=1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_SPAM=0.5, SPF_PASS=-0.001, URI_HEX=1.313] autolearn=disabled Authentication-Results: spamd4-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id B3qtGRQ1WDn7 for ; Sat, 19 Aug 2017 13:17:54 +0000 (UTC) Received: from mail-it0-f45.google.com (mail-it0-f45.google.com [209.85.214.45]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id E28485F6C2 for ; Sat, 19 Aug 2017 13:17:53 +0000 (UTC) Received: by mail-it0-f45.google.com with SMTP id 76so16910372ith.0 for ; Sat, 19 Aug 2017 06:17:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to; bh=8Hu1eSaXUUBJm1ACDZ3TwHCJUQejJxKCYnngYjELpXA=; b=nFx1g22GCza/08mc2xtcysSnmK/4JK9XoEkUuN84mWcPgP0NgaY9GHSeW9reVMTqox 0KdpSXGAYmjVHA+MBdRJyJrstgpxzO1t6/lCFRceUZEe5wHqXdGBmZsacjfZiv/TYkQc J+WdzQjnB/CV7xz9qvJACcHUvDNJ6TLGO8slwp2GEvviUCI8OSAmpjfMG3M2ZQBmy6gX fzx30X6t5RMU+k31YgTIvZw+eAoWg2bO/Iq6T2w7AL5tJVn8x1z7wDFObqJQvV1N/5YV 0TJW2C3h2tRRReWwIY5y9QHs59QAwXZc28hC7Rm37Mo3zYU5Ybf1NNqmTBxJlyFQBTXE H+bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to; bh=8Hu1eSaXUUBJm1ACDZ3TwHCJUQejJxKCYnngYjELpXA=; b=UqAZa5Zck9TA3ZVDpXFjYjA11vjvO/sFI0g1sGlONNVGKXe9MW/th3Puty8WvjmzBg 6LS90xslgiQL04PZHAK2iG7ww/Rn3rhxKaxWLM9GOlY6rW/wMa/UJz2zu1WNDseBDNbU 6kvtw3ct/DuLMDt0DJ1L5M+P4na6em1UmLRnW5ESiasNebu1MH/cIfxd+QOndv888tiW 08ushK2nauUHjso6XBIg1M3JHPGQOSw+/S6zV5giwXBJrg0C7NPGnbSziunNtkQyWOp2 dwL5gVSwj4h2nzueZYhmZc4qwE5LYqdCYVY7Aty+MGFipZ7Vwtas3juo1Q4htBfrPKCy haYg== X-Gm-Message-State: AHYfb5ieGIKyoioXRCbV5y+lV8rxeBIgYlDrk2OLIw6t6joeRvNZcdjl Sl04ZX77MvVYIPidvpLUPJJkOdI48w== X-Received: by 10.36.51.2 with SMTP id k2mr1068415itk.155.1503148672261; Sat, 19 Aug 2017 06:17:52 -0700 (PDT) MIME-Version: 1.0 Sender: tbain98@gmail.com Received: by 10.2.2.193 with HTTP; Sat, 19 Aug 2017 06:17:51 -0700 (PDT) Received: by 10.2.2.193 with HTTP; Sat, 19 Aug 2017 06:17:51 -0700 (PDT) In-Reply-To: References: <1503077176934-4729814.post@n4.nabble.com> <1503079193215-4729816.post@n4.nabble.com> <32fea7da-303d-02d2-466a-a3d18040abad@gmail.com> From: Tim Bain Date: Sat, 19 Aug 2017 07:17:51 -0600 X-Google-Sender-Auth: noUFmzlu14vAxz0zqkGoBDwZLiM Message-ID: Subject: Re: Close message listener decoupled To: ActiveMQ Users Content-Type: multipart/alternative; boundary="001a1143e53aa7b4d405571b124a" archived-at: Sat, 19 Aug 2017 13:18:00 -0000 --001a1143e53aa7b4d405571b124a Content-Type: text/plain; charset="UTF-8" One other problem with the implementation: you provided a MessageListener of your own definition, which doesn't do anything, which means your consumer has no way to get the messages. A better alternative would be to have your register method take the MessageListener object (of the consumer's definition, not your own) as an argument. Tim On Aug 18, 2017 1:02 PM, "Justin Bertram" wrote: > > I can't see any reason why anyone would ever not want to use ActiveMQ ;) > > I agree. However, based on his code he's using 5.x right now, and I can > imagine a day when he'd want to move to ActiveMQ Artemis. :) > > > Justin > > On Fri, Aug 18, 2017 at 1:59 PM, Timothy Bish wrote: > > > On 08/18/2017 02:49 PM, Justin Bertram wrote: > > > >> I see a couple of potential problems with this code: > >> > >> 1) It's littered with non-JMS code (e.g. ActiveMQConnectionFactory, > >> ActiveMQConnection). You may not care about that if this application > will > >> only ever integrate with ActiveMQ, but if you think you'll ever want to > >> use > >> any other kind of JMS broker then you'll have to rewrite some of this > >> stuff > >> when you migrate. APIs are standardized for a reason. Deviate at your > >> own > >> risk. > >> > > > > I can't see any reason why anyone would ever not want to use ActiveMQ ;) > > > > > > > >> 2) Every time you invoke register() you create a new Connection, > Session, > >> Consumer, etc. This is an anti-pattern. Connection objects are "heavy" > >> and are meant to be shared. > >> > >> 3) You do not keep track of any of the resources you create (i.e. > >> Connection, Session, Consumer) so you have no way to clean them up. > >> > >> > maybe the strcture is not good at all > >> > >> I'd agree with that. > >> > >> > >> Justin > >> > >> On Fri, Aug 18, 2017 at 12:59 PM, Juleian > wrote: > >> > >> That sounds reasonable actually. The only problem I also somehow have is > >>> when > >>> register is called the method "is stuck" in the thread that is opened > or > >>> not? I do not see how I can return a value with this structure (maybe > the > >>> strcture is not good at all, its my first real programming task). > >>> > >>> public register(String topicName) { > >>> > >>> > >>> > >>> > >>> > >>> try { > >>> > >>> // create connection to Broker, create Session > >>> and > >>> Consumer > >>> > >>> ActiveMQConnectionFactory connectionFactory = > >>> new > >>> ActiveMQConnectionFactory( > >>> "tcp://localhost:61616"); > >>> ActiveMQConnection connection = > >>> (ActiveMQConnection) > >>> connectionFactory.createConnection(); > >>> connection.start(); > >>> Session session = > connection.createSession(false > >>> , > >>> Session.AUTO_ACKNOWLEDGE); > >>> Topic topicObject = > >>> session.createTopic(topicName) > >>> ; > >>> MessageConsumer consumer = > >>> session.createConsumer( > >>> topicObject); > >>> > >>> > >>> //check if topic is available on Broker > >>> > >>> > >>> > >>> DestinationSource ds = connection. > >>> getDestinationSource(); > >>> > >>> Set topics = ds.getTopics(); > >>> String compare = topicName; > >>> int count = 0; > >>> > >>> for(ActiveMQTopic topic : topics){ > >>> > >>> > >>> > >>> if(compare.equals(topic.getTopicName())) > { > >>> > >>> System.out.println("Found " + > >>> topic.getTopicName()); > >>> count = count + 1; > >>> > >>> > >>> } > >>> > >>> } > >>> > >>> if(count == 0){ > >>> > >>> > >>> System.out.println("The topic you want > >>> to > >>> subscribe to is not > >>> found."); > >>> System.out.println("Please try again > >>> with > >>> a valid topic name."); > >>> > >>> return; > >>> > >>> } > >>> > >>> > >>> > >>> > >>> //register Component at mongoDB > >>> > >>> > >>> > >>> MessageListener listner = new > MessageListener() > >>> { > >>> > >>> @Override > >>> public void onMessage(Message > message) > >>> { > >>> try { > >>> if (message instanceof TextMessage) { > >>> TextMessage textMessage = (TextMessage) > >>> message; > >>> System.out.println("Received message : " > >>> + textMessage.getText() + "'"); > >>> } > >>> } catch (JMSException e) { > >>> System.out.println("Caught:" + e); > >>> } > >>> } > >>> }; > >>> consumer.setMessageListener(listner); > >>> > >>> try { > >>> System.in.read(); > >>> } catch (IOException e) { > >>> } > >>> > >>> } catch (JMSException ex) { > >>> // Logger.getLogger(Consumer.class.getName()).log(Level. > >>> SEVERE, > >>> null, ex); > >>> > >>> } > >>> > >>> > >>> > >>> } > >>> > >>> > >>> > >>> > >>> -- > >>> View this message in context: http://activemq.2283324.n4. > >>> nabble.com/Close-message-listener-decoupled-tp4729814p4729816.html > >>> Sent from the ActiveMQ - User mailing list archive at Nabble.com. > >>> > >>> > > -- > > Tim Bish > > twitter: @tabish121 > > blog: http://timbish.blogspot.com/ > > > > > --001a1143e53aa7b4d405571b124a--