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);
}
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);
}
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;
}
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));
}
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;
}
Aggregations