Return-Path: Delivered-To: apmail-activemq-users-archive@www.apache.org Received: (qmail 48005 invoked from network); 4 Mar 2011 17:19:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 4 Mar 2011 17:19:48 -0000 Received: (qmail 71118 invoked by uid 500); 4 Mar 2011 17:19:47 -0000 Delivered-To: apmail-activemq-users-archive@activemq.apache.org Received: (qmail 71056 invoked by uid 500); 4 Mar 2011 17:19:47 -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 71048 invoked by uid 99); 4 Mar 2011 17:19:47 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Mar 2011 17:19:47 +0000 X-ASF-Spam-Status: No, hits=1.3 required=5.0 tests=SPF_PASS,URI_HEX X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [62.75.158.78] (HELO mail.liquid-reality.de) (62.75.158.78) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Mar 2011 17:19:42 +0000 Received: from [10.0.0.102] (HSI-KBW-091-089-013-105.hsi2.kabelbw.de [91.89.13.105]) by mail.liquid-reality.de (Postfix) with ESMTP id 7AA7AB38010 for ; Fri, 4 Mar 2011 17:19:20 +0000 (UTC) Message-ID: <4D711F14.4040703@die-schneider.net> Date: Fri, 04 Mar 2011 18:19:16 +0100 From: Christian Schneider User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.14) Gecko/20110221 Lightning/1.0b2 Thunderbird/3.1.8 MIME-Version: 1.0 To: users@activemq.apache.org Subject: Re: Best practices with JMS References: <4D711C39.3090105@gmail.com> In-Reply-To: <4D711C39.3090105@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi Filip, basically connections can be kept open as long as you like. They are also thread safe. For connections there is the problem that they can become invalid if the server goes away for too long. Sessions can also be kept open but they are not thread safe. So make sure you do not share a session between threads. I suggest that you take a look at the spring jms abstractions. They help with a lot of the problems you may have. The keywords you need JmsTemplate, DefaultMessageListenerContainer. Be careful though. The spring jmstemplate always closes the connection after a request. So you have to use a pooling connection factory. Application servers sometimes provide these. When doing a standalone application you may want to wrap the connection factory in a spring CachingConnectionFactory. Frameworks like Camel and CXF use this aproach as it makes life a lot easier than working with JMS directly. If your focus is on simply sending and receiving your objects in a really easy way you might even want to use Apache Camel. http://camel.apache.org/jms.html http://camel.apache.org/pojo-messaging-example.html Messaging canĀ“t be easier than with camel and it embeds nicely in your application. Best regards Christian Am 04.03.2011 18:07, schrieb Filip Nguyen: > I am using ActiveMQ and I am reading Java Message Service document > which specifies the JMS JSR. However I cant find anywhere what are the > best practices for Connection length. From the JMS JSR I understand that: > > Connection is Heavy weight object as JMS JSR suggests. So its ok to > create it at start of the application and release it just before > application closes > > Going further the Session is supposed to be lightweight object so > there should be no problem to create it more often. Butas indicated > here: > http://activemq.2283324.n4.nabble.com/receiveNoWait-problem-td2347600.html > there is James.Strachan suggests to use 1 consumer for whole > application to aovid receivenowait problems. > > My questions are (assuming I want to avoid requestNoWait problems and > i dont want to call receive(1000)): > > 1. How long should connection be opened (after calling start()) and > are there > any problems with having it opened for a long long time? > 2. How long should one Session be opened? (this relates to > MessageConsumer > because I assume the consumer needs to have session opened). > > Filip Nguyen > -- ---- http://www.liquid-reality.de