14.3. Optimizing Client-Side JMS Performance
import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.pool.PooledConnectionFactory; ConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616"); PooledConnectionFactory pcf = new PooledConnectionFactory(); //Set expiry timeout because the default (0) prevents reconnection on failure pcf.setExpiryTimeout(5000); pcf.setConnectionFactory(cf); JMSConfiguration jmsConfig = new JMSConfiguration(); jmsConfig.setConnectionFactory(pdf);
Avoiding synchronous receives
Consumer.receive()method when it needs to share queues between endpoints. This scenario requires the
MessageListenerto use a message selector to filter the messages. The message selector must be known in advance, so the
MessageListeneris opened only once.
- When JMSMessageID is used as the JMSCorrelationIDIf the JMS properties useConduitIdSelector and conduitSelectorPrefix are not set on the JMS transport, the client does not set a JMSCorrelationId. This causes the server to use the JMSMessageId of the request message as the JMSCorrelationId. As JMSMessageID cannot be known in advance, the client has to use a synchronous
Consumer.receive()method.Note that you must use the
Consumer.receive()method with IBM JMS endpoints (their default).
- The user sets the JMStype in the request message and then sets a custom JMSCorrelationID.Again, as the custom JMSCorrelationID cannot be known in advance, the client has to use a synchronous