qpid-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robbie Gemmell <robbie.gemm...@gmail.com>
Subject Re: JMS Client usage - best practices?
Date Tue, 10 Jan 2012 14:41:15 GMT
Hi Praveen,

Using either JNDI or Session.createQueue should work fine, but the
obvious limitation of the latter is that the (possibly
provider-specific) configuration is then part of your code (unless you
look the information up somewhere before using it) and cant be changed
without modifying the code.

To better answer the other question, it would be good to first know
more specifics about the application and its messaging model, eg:
How many instances of the application are you likely to be running?
Will all your messages be persistent?
Will you always use transactions (and if so will it always of batch
size 1 like below)?
You mention having maybe 5-10 concurrent publishers, but how many
different Destinations are you likely to be sending to in total?
Are any of the above Destinations likely to be used a lot more than the others?


On 10 January 2012 00:27, Praveen M <lefthandmagic@gmail.com> wrote:
> Hi,
>   I'm writing a JMS Client and have a few best practices questions.
> 1) I understand that there are different ways ways to create a reference to
> a destination to enqueue a message (using JMS createQueue, using JNDI
> lookup).
>    What would be the recommended way to use?
> 2) I create a connection to the broker on my application startup, and
> create a session pool. on every enqueue, i checkout a session from my pool
> use it and return to pool on enqueue.
>    Does this sound reasonable?  (code sample below)
>    What would be the pattern that is typically used/recommended for
> session management/connection management in the client side?
>    Or is this an overkill to do? Is CreateSession() and CreateProducer()
> really cheap that it is just done on each enqueue?
>    In my use case, I'd expect quite some concurrency (assume n (maybe
> 5-10) threads doing enqueues at the same time) and I'd prefer it to not
> lock/block and go through asap.
>    I do remember from reading the qpid client code that there is a lock
> held on the connection object whenever a new session is created on that
> connection. I'm assuming it is one of the places where my enqueue can slow
> down
>    when going in parallel if it has to create a session for every enqueue
> of a message. There might be more such blocks, which I'm not aware of.
>   Taking performance into mind, what would be the best design for
> session/connection management?
>    A snippet of what I have currently is below,
>    // a thread safe queue with the available session producer pairs which
> can be used to create a message and enqueue.
>    ConcurrentLinkedQueue<Pair<Session, MessageProducer>>
> availableSessionProducerPairs = new ConcurrentLinkedQueue<Pair<Session,
> MessageProducer>> ();
>   // initialize the sessionProducerPairs, create upto n pairs
>    initializePool(Connection qpidConnection) {
>         for (int i = 1 ; i <= SESSION_PRODUCER_PAIRS_COUNT; i ++ ) {
>            Session session = qpidConnection.createSession(true,
>            MessageProducer producer = session.createProducer(null);
>            availableSessionProducerPairs.add(Pair.newPair(session,
> producer));
>        }
>    }
> // on enqueue we checkout a session/producer pair use it for the enqueue
> and then return it back to the session/produer pair pool.
>   enqueueMessage(String queueName, byte[] message) {
>            // remove the session producer pair
>             Pair<Session, MessageProducer> sessionProducerPair =
> availableSessionProducerPairs.poll();
>        if(sessionProducerPair == null) {
>            // gack here and return null.
>        }
>        Session session = sessionProducerPair.getFirst();
>        MessageProducer producer = sessionProducerPair.getSecond();
>        BytesMessage jmsMessage = session.createBytesMessage();
>        jmsMessage.writeBytes(message);
>        Queue queueRef = queueNameToReferenceMap.get(queueName);
>        producer.send(queueRef, jmsMessage, DeliveryMode.PERSISTENT, 0, 0);
>        session.commit();
>        availableSessionProducersPair.add()
>  }
> Thank you,
> -Praveen

Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org

View raw message