Search in sources :

Example 1 with ActiveMQPrefetchPolicy

use of org.apache.activemq.ActiveMQPrefetchPolicy in project activemq-artemis by apache.

the class AdvisoryTests method xtestMessageDiscardedAdvisory.

public void xtestMessageDiscardedAdvisory() throws Exception {
    Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Topic topic = s.createTopic(getClass().getName());
    MessageConsumer consumer = s.createConsumer(topic);
    assertNotNull(consumer);
    Topic advisoryTopic = AdvisorySupport.getMessageDiscardedAdvisoryTopic((ActiveMQDestination) topic);
    MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
    // start throwing messages at the consumer
    MessageProducer producer = s.createProducer(topic);
    int count = (new ActiveMQPrefetchPolicy().getTopicPrefetch() * 2);
    for (int i = 0; i < count; i++) {
        BytesMessage m = s.createBytesMessage();
        producer.send(m);
    }
    Message msg = advisoryConsumer.receive(1000);
    assertNotNull(msg);
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) BytesMessage(javax.jms.BytesMessage) Message(javax.jms.Message) ActiveMQPrefetchPolicy(org.apache.activemq.ActiveMQPrefetchPolicy) BytesMessage(javax.jms.BytesMessage) MessageProducer(javax.jms.MessageProducer) Topic(javax.jms.Topic) Session(javax.jms.Session)

Example 2 with ActiveMQPrefetchPolicy

use of org.apache.activemq.ActiveMQPrefetchPolicy in project activemq-artemis by apache.

the class JmsTransactionTestSupport method setPrefetchToOne.

/**
 * Sets the prefeftch policy to one.
 */
protected void setPrefetchToOne() {
    ActiveMQPrefetchPolicy prefetchPolicy = getPrefetchPolicy();
    prefetchPolicy.setQueuePrefetch(1);
    prefetchPolicy.setTopicPrefetch(1);
    prefetchPolicy.setDurableTopicPrefetch(1);
    prefetchPolicy.setOptimizeDurableTopicPrefetch(1);
}
Also used : ActiveMQPrefetchPolicy(org.apache.activemq.ActiveMQPrefetchPolicy)

Example 3 with ActiveMQPrefetchPolicy

use of org.apache.activemq.ActiveMQPrefetchPolicy in project activemq-artemis by apache.

the class SlowConsumerTopicTest method createConnectionFactory.

@Override
protected ActiveMQConnectionFactory createConnectionFactory(String uri) throws Exception {
    ActiveMQConnectionFactory result = super.createConnectionFactory(uri);
    ActiveMQPrefetchPolicy policy = new ActiveMQPrefetchPolicy();
    policy.setTopicPrefetch(10);
    result.setPrefetchPolicy(policy);
    return result;
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ActiveMQPrefetchPolicy(org.apache.activemq.ActiveMQPrefetchPolicy)

Example 4 with ActiveMQPrefetchPolicy

use of org.apache.activemq.ActiveMQPrefetchPolicy in project activemq-artemis by apache.

the class TopicProducerFlowControlTest method testTopicProducerFlowControl.

public void testTopicProducerFlowControl() throws Exception {
    // Create the connection factory
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerUrl);
    connectionFactory.setAlwaysSyncSend(true);
    connectionFactory.setProducerWindowSize(1024);
    ActiveMQPrefetchPolicy prefetchPolicy = new ActiveMQPrefetchPolicy();
    prefetchPolicy.setAll(5000);
    connectionFactory.setPrefetchPolicy(prefetchPolicy);
    // Start the test destination listener
    Connection c = connectionFactory.createConnection();
    c.start();
    Session listenerSession = c.createSession(false, 1);
    Destination destination = createDestination(listenerSession);
    listenerSession.createConsumer(destination).setMessageListener(new TopicProducerFlowControlTest());
    final AtomicInteger blockedCounter = new AtomicInteger(0);
    listenerSession.createConsumer(new ActiveMQTopic(AdvisorySupport.FULL_TOPIC_PREFIX + ">")).setMessageListener(new MessageListener() {

        @Override
        public void onMessage(Message message) {
            LOG.info("Got full advisory, blockedCounter: " + blockedCounter.get());
            blockedCounter.incrementAndGet();
        }
    });
    // Start producing the test messages
    final Session session = connectionFactory.createConnection().createSession(false, Session.AUTO_ACKNOWLEDGE);
    final MessageProducer producer = session.createProducer(destination);
    Thread producingThread = new Thread("Producing Thread") {

        @Override
        public void run() {
            try {
                for (long i = 0; i < numMessagesToSend; i++) {
                    producer.send(session.createTextMessage("test"));
                    long count = produced.incrementAndGet();
                    if (count % 10000 == 0) {
                        LOG.info("Produced " + count + " messages");
                    }
                }
            } catch (Throwable ex) {
                ex.printStackTrace();
            } finally {
                try {
                    producer.close();
                    session.close();
                } catch (Exception e) {
                }
            }
        }
    };
    producingThread.start();
    Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return consumed.get() == numMessagesToSend;
        }
    }, // give it plenty of time before failing
    5 * 60 * 1000);
    assertEquals("Didn't produce all messages", numMessagesToSend, produced.get());
    assertEquals("Didn't consume all messages", numMessagesToSend, consumed.get());
    assertTrue("Producer got blocked", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return blockedCounter.get() > 0;
        }
    }, 5 * 1000));
}
Also used : Destination(javax.jms.Destination) ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) Message(javax.jms.Message) Connection(javax.jms.Connection) MessageListener(javax.jms.MessageListener) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ActiveMQPrefetchPolicy(org.apache.activemq.ActiveMQPrefetchPolicy) MessageProducer(javax.jms.MessageProducer) Wait(org.apache.activemq.util.Wait) Session(javax.jms.Session)

Example 5 with ActiveMQPrefetchPolicy

use of org.apache.activemq.ActiveMQPrefetchPolicy in project activemq-artemis by apache.

the class TwoBrokerQueueClientsReconnectTest method setUp.

@Override
public void setUp() throws Exception {
    super.setAutoFail(true);
    super.setUp();
    createBroker(new URI("broker:(tcp://localhost:61616)/BrokerA?persistent=false&useJmx=true"));
    createBroker(new URI("broker:(tcp://localhost:61617)/BrokerB?persistent=false&useJmx=true"));
    // Configure broker connection factory
    ActiveMQConnectionFactory factoryA;
    ActiveMQConnectionFactory factoryB;
    factoryA = (ActiveMQConnectionFactory) getConnectionFactory("BrokerA");
    factoryB = (ActiveMQConnectionFactory) getConnectionFactory("BrokerB");
    // Set prefetch policy
    ActiveMQPrefetchPolicy policy = new ActiveMQPrefetchPolicy();
    policy.setAll(PREFETCH_COUNT);
    factoryA.setPrefetchPolicy(policy);
    factoryB.setPrefetchPolicy(policy);
    msgsClient1 = 0;
    msgsClient2 = 0;
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ActiveMQPrefetchPolicy(org.apache.activemq.ActiveMQPrefetchPolicy) URI(java.net.URI)

Aggregations

ActiveMQPrefetchPolicy (org.apache.activemq.ActiveMQPrefetchPolicy)13 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)9 Session (javax.jms.Session)4 Connection (javax.jms.Connection)3 Destination (javax.jms.Destination)2 Message (javax.jms.Message)2 MessageProducer (javax.jms.MessageProducer)2 URI (java.net.URI)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BytesMessage (javax.jms.BytesMessage)1 MessageConsumer (javax.jms.MessageConsumer)1 MessageListener (javax.jms.MessageListener)1 Topic (javax.jms.Topic)1 ObjectName (javax.management.ObjectName)1 ActiveMQMessageConsumer (org.apache.activemq.ActiveMQMessageConsumer)1 TransportConnector (org.apache.activemq.broker.TransportConnector)1 DestinationViewMBean (org.apache.activemq.broker.jmx.DestinationViewMBean)1 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)1 ActiveMQMessage (org.apache.activemq.command.ActiveMQMessage)1 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)1