protected ActiveMQPrefetchPolicy getPrefetchPolicy() { return ((ActiveMQConnection)connection).getPrefetchPolicy(); }
/** * @throws JMSException */ private ActiveMQMessageConsumer createConsumer() throws JMSException { browseDone.set(false); ActiveMQPrefetchPolicy prefetchPolicy = session.connection.getPrefetchPolicy(); return new ActiveMQMessageConsumer(session, consumerId, destination, null, selector, prefetchPolicy.getQueueBrowserPrefetch(), prefetchPolicy .getMaximumPendingMessageLimit(), false, true, dispatchAsync, null) { public void dispatch(MessageDispatch md) { if (md.getMessage() == null) { browseDone.set(true); } else { super.dispatch(md); } notifyMessageAvailable(); } }; }
/** * Creates a <CODE>QueueReceiver</CODE> object to receive messages from * the specified queue using a message selector. * * @param queue the <CODE>Queue</CODE> to access * @param messageSelector only messages with properties matching the message * selector expression are delivered. A value of null or an * empty string indicates that there is no message selector * for the message consumer. * @return QueueReceiver * @throws JMSException if the session fails to create a receiver due to * some internal error. * @throws InvalidDestinationException if an invalid queue is specified. * @throws InvalidSelectorException if the message selector is invalid. */ @Override public QueueReceiver createReceiver(Queue queue, String messageSelector) throws JMSException { checkClosed(); if (queue instanceof CustomDestination) { CustomDestination customDestination = (CustomDestination)queue; return customDestination.createReceiver(this, messageSelector); } ActiveMQPrefetchPolicy prefetchPolicy = this.connection.getPrefetchPolicy(); return new ActiveMQQueueReceiver(this, getNextConsumerId(), ActiveMQMessageTransformation.transformDestination(queue), messageSelector, prefetchPolicy.getQueuePrefetch(), prefetchPolicy.getMaximumPendingMessageLimit(), asyncDispatch); }
ActiveMQPrefetchPolicy prefetchPolicy = this.connection.getPrefetchPolicy(); return new ActiveMQTopicSubscriber(this, getNextConsumerId(), ActiveMQMessageTransformation.transformDestination(topic), null, messageSelector, prefetchPolicy .getTopicPrefetch(), prefetchPolicy.getMaximumPendingMessageLimit(), noLocal, false, asyncDispatch);
ActiveMQPrefetchPolicy prefetchPolicy = connection.getPrefetchPolicy(); int prefetch = 0; if (destination instanceof Topic) {
ActiveMQPrefetchPolicy prefetchPolicy = this.connection.getPrefetchPolicy(); int prefetch = isAutoAcknowledge() && connection.isOptimizedMessageDispatch() ? prefetchPolicy.getOptimizeDurableTopicPrefetch() : prefetchPolicy.getDurableTopicPrefetch(); int maxPrendingLimit = prefetchPolicy.getMaximumPendingMessageLimit();
protected ActiveMQPrefetchPolicy getPrefetchPolicy() { return connection.getPrefetchPolicy(); }
/** * @throws JMSException */ private ActiveMQMessageConsumer createConsumer() throws JMSException { browseDone.set(false); ActiveMQPrefetchPolicy prefetchPolicy = session.connection.getPrefetchPolicy(); return new ActiveMQMessageConsumer(session, consumerId, destination, null, selector, prefetchPolicy.getQueueBrowserPrefetch(), prefetchPolicy .getMaximumPendingMessageLimit(), false, true, dispatchAsync, null) { public void dispatch(MessageDispatch md) { if (md.getMessage() == null) { browseDone.set(true); } else { super.dispatch(md); } notifyMessageAvailable(); } }; }
/** * @throws JMSException */ private ActiveMQMessageConsumer createConsumer() throws JMSException { browseDone.set(false); ActiveMQPrefetchPolicy prefetchPolicy = session.connection.getPrefetchPolicy(); return new ActiveMQMessageConsumer(session, consumerId, destination, null, selector, prefetchPolicy.getQueueBrowserPrefetch(), prefetchPolicy .getMaximumPendingMessageLimit(), false, true, dispatchAsync, null) { public void dispatch(MessageDispatch md) { if (md.getMessage() == null) { browseDone.set(true); } else { super.dispatch(md); } notifyMessageAvailable(); } }; }
/** * @throws JMSException */ private ActiveMQMessageConsumer createConsumer() throws JMSException { browseDone.set(false); ActiveMQPrefetchPolicy prefetchPolicy = session.connection.getPrefetchPolicy(); return new ActiveMQMessageConsumer(session, consumerId, destination, null, selector, prefetchPolicy.getQueueBrowserPrefetch(), prefetchPolicy .getMaximumPendingMessageLimit(), false, true, dispatchAsync, null) { public void dispatch(MessageDispatch md) { if (md.getMessage() == null) { browseDone.set(true); } else { super.dispatch(md); } notifyMessageAvailable(); } }; }
/** * @param session * @param originalDestination * @param selectorExpression * @param cnum * @return * @throws JMSException */ private ActiveMQMessageConsumer createConsumer() throws JMSException { browseDone.set(false); ActiveMQPrefetchPolicy prefetchPolicy = session.connection.getPrefetchPolicy(); return new ActiveMQMessageConsumer(session, consumerId, destination, null, selector, prefetchPolicy.getQueueBrowserPrefetch(), prefetchPolicy .getMaximumPendingMessageLimit(), false, true, dispatchAsync, null) { public void dispatch(MessageDispatch md) { if (md.getMessage() == null) { browseDone.set(true); } else { super.dispatch(md); } notifyMessageAvailable(); } }; }
@Test public void testMessageListenerWithConsumerWithPrefetch1() throws Exception { final AtomicInteger counter = new AtomicInteger(0); final CountDownLatch done = new CountDownLatch(1); // Receive a message with the JMS API connection.getPrefetchPolicy().setAll(1); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); ActiveMQDestination destination = createDestination(session, destinationType); MessageConsumer consumer = session.createConsumer(destination); consumer.setMessageListener(new MessageListener() { @Override public void onMessage(Message m) { counter.incrementAndGet(); if (counter.get() == 4) { done.countDown(); } } }); // Send the messages sendMessages(session, destination, 4); assertTrue(done.await(1000, TimeUnit.MILLISECONDS)); Thread.sleep(200); // Make sure only 4 messages were delivered. assertEquals(4, counter.get()); }
/** * Creates a <CODE>QueueReceiver</CODE> object to receive messages from * the specified queue using a message selector. * * @param queue the <CODE>Queue</CODE> to access * @param messageSelector only messages with properties matching the message * selector expression are delivered. A value of null or an * empty string indicates that there is no message selector * for the message consumer. * @return QueueReceiver * @throws JMSException if the session fails to create a receiver due to * some internal error. * @throws InvalidDestinationException if an invalid queue is specified. * @throws InvalidSelectorException if the message selector is invalid. */ @Override public QueueReceiver createReceiver(Queue queue, String messageSelector) throws JMSException { checkClosed(); if (queue instanceof CustomDestination) { CustomDestination customDestination = (CustomDestination)queue; return customDestination.createReceiver(this, messageSelector); } ActiveMQPrefetchPolicy prefetchPolicy = this.connection.getPrefetchPolicy(); return new ActiveMQQueueReceiver(this, getNextConsumerId(), ActiveMQMessageTransformation.transformDestination(queue), messageSelector, prefetchPolicy.getQueuePrefetch(), prefetchPolicy.getMaximumPendingMessageLimit(), asyncDispatch); }
/** * Creates a <CODE>QueueReceiver</CODE> object to receive messages from * the specified queue using a message selector. * * @param queue the <CODE>Queue</CODE> to access * @param messageSelector only messages with properties matching the message * selector expression are delivered. A value of null or an * empty string indicates that there is no message selector * for the message consumer. * @return QueueReceiver * @throws JMSException if the session fails to create a receiver due to * some internal error. * @throws InvalidDestinationException if an invalid queue is specified. * @throws InvalidSelectorException if the message selector is invalid. */ @Override public QueueReceiver createReceiver(Queue queue, String messageSelector) throws JMSException { checkClosed(); if (queue instanceof CustomDestination) { CustomDestination customDestination = (CustomDestination)queue; return customDestination.createReceiver(this, messageSelector); } ActiveMQPrefetchPolicy prefetchPolicy = this.connection.getPrefetchPolicy(); return new ActiveMQQueueReceiver(this, getNextConsumerId(), ActiveMQMessageTransformation.transformDestination(queue), messageSelector, prefetchPolicy.getQueuePrefetch(), prefetchPolicy.getMaximumPendingMessageLimit(), asyncDispatch); }
/** * Creates a <CODE>QueueReceiver</CODE> object to receive messages from * the specified queue using a message selector. * * @param queue the <CODE>Queue</CODE> to access * @param messageSelector only messages with properties matching the message * selector expression are delivered. A value of null or an * empty string indicates that there is no message selector * for the message consumer. * @return QueueReceiver * @throws JMSException if the session fails to create a receiver due to * some internal error. * @throws InvalidDestinationException if an invalid queue is specified. * @throws InvalidSelectorException if the message selector is invalid. */ public QueueReceiver createReceiver(Queue queue, String messageSelector) throws JMSException { checkClosed(); if (queue instanceof CustomDestination) { CustomDestination customDestination = (CustomDestination)queue; return customDestination.createReceiver(this, messageSelector); } ActiveMQPrefetchPolicy prefetchPolicy = this.connection.getPrefetchPolicy(); return new ActiveMQQueueReceiver(this, getNextConsumerId(), ActiveMQMessageTransformation.transformDestination(queue), messageSelector, prefetchPolicy.getQueuePrefetch(), prefetchPolicy.getMaximumPendingMessageLimit(), asyncDispatch); }
/** * Creates a <CODE>QueueReceiver</CODE> object to receive messages from * the specified queue using a message selector. * * @param queue the <CODE>Queue</CODE> to access * @param messageSelector only messages with properties matching the message * selector expression are delivered. A value of null or an * empty string indicates that there is no message selector * for the message consumer. * @return QueueReceiver * @throws JMSException if the session fails to create a receiver due to * some internal error. * @throws InvalidDestinationException if an invalid queue is specified. * @throws InvalidSelectorException if the message selector is invalid. */ @Override public QueueReceiver createReceiver(Queue queue, String messageSelector) throws JMSException { checkClosed(); if (queue instanceof CustomDestination) { CustomDestination customDestination = (CustomDestination)queue; return customDestination.createReceiver(this, messageSelector); } ActiveMQPrefetchPolicy prefetchPolicy = this.connection.getPrefetchPolicy(); return new ActiveMQQueueReceiver(this, getNextConsumerId(), ActiveMQMessageTransformation.transformDestination(queue), messageSelector, prefetchPolicy.getQueuePrefetch(), prefetchPolicy.getMaximumPendingMessageLimit(), asyncDispatch); }
ActiveMQPrefetchPolicy prefetchPolicy = this.connection.getPrefetchPolicy(); return new ActiveMQTopicSubscriber(this, getNextConsumerId(), ActiveMQMessageTransformation.transformDestination(topic), null, messageSelector, prefetchPolicy .getTopicPrefetch(), prefetchPolicy.getMaximumPendingMessageLimit(), noLocal, false, asyncDispatch);
ActiveMQPrefetchPolicy prefetchPolicy = this.connection.getPrefetchPolicy(); return new ActiveMQTopicSubscriber(this, getNextConsumerId(), ActiveMQMessageTransformation.transformDestination(topic), null, messageSelector, prefetchPolicy .getTopicPrefetch(), prefetchPolicy.getMaximumPendingMessageLimit(), noLocal, false, asyncDispatch);
@Test public void testMutiReceiveWithPrefetch1() throws Exception { // Set prefetch to 1 connection.getPrefetchPolicy().setAll(1); connection.start(); // Use all the ack modes Session session = connection.createSession(false, ackMode); destination = createDestination(session, destinationType); MessageConsumer consumer = session.createConsumer(destination); // Send the messages sendMessages(session, destination, 4); System.out.println("messages are sent."); // Make sure 4 messages were delivered. Message message = null; for (int i = 0; i < 4; i++) { message = consumer.receive(5000); System.out.println("message received: " + message + " ack mode: " + ackMode); assertNotNull(message); } assertNull(consumer.receiveNoWait()); message.acknowledge(); }
connection.getPrefetchPolicy().setAll(1); connection.start(); connection.getPrefetchPolicy().setAll(1); connection.start();