Java Code Examples for org.apache.activemq.ActiveMQConnectionFactory#setPrefetchPolicy()

The following examples show how to use org.apache.activemq.ActiveMQConnectionFactory#setPrefetchPolicy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NetworkBrokerDetachTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected ConnectionFactory createConnectionFactory(final BrokerService broker) throws Exception {
   String url = broker.getTransportConnectors().get(0).getServer().getConnectURI().toString();
   ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
   connectionFactory.setOptimizedMessageDispatch(true);
   connectionFactory.setCopyMessageOnSend(false);
   connectionFactory.setUseCompression(false);
   connectionFactory.setDispatchAsync(false);
   connectionFactory.setUseAsyncSend(false);
   connectionFactory.setOptimizeAcknowledge(false);
   connectionFactory.setWatchTopicAdvisories(true);
   ActiveMQPrefetchPolicy qPrefetchPolicy = new ActiveMQPrefetchPolicy();
   qPrefetchPolicy.setQueuePrefetch(100);
   qPrefetchPolicy.setTopicPrefetch(1000);
   connectionFactory.setPrefetchPolicy(qPrefetchPolicy);
   connectionFactory.setAlwaysSyncSend(true);
   return connectionFactory;
}
 
Example 2
Source File: NetworkLoadTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected Connection createConnection(int brokerId) throws JMSException {
   ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:" + (60000 + brokerId));
   connectionFactory.setOptimizedMessageDispatch(true);
   connectionFactory.setCopyMessageOnSend(false);
   connectionFactory.setUseCompression(false);
   connectionFactory.setDispatchAsync(true);
   connectionFactory.setUseAsyncSend(false);
   connectionFactory.setOptimizeAcknowledge(false);
   connectionFactory.setWatchTopicAdvisories(false);
   ActiveMQPrefetchPolicy qPrefetchPolicy = new ActiveMQPrefetchPolicy();
   qPrefetchPolicy.setQueuePrefetch(100);
   qPrefetchPolicy.setTopicPrefetch(1000);
   connectionFactory.setPrefetchPolicy(qPrefetchPolicy);
   connectionFactory.setAlwaysSyncSend(true);
   return connectionFactory.createConnection();
}
 
Example 3
Source File: ActiveMQMailQueueBlobTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@BeforeEach
public void setUp(BrokerService broker, MailQueueMetricExtension.MailQueueMetricTestSystem metricTestSystem) {
    fileSystem = new MyFileSystem();
    ActiveMQConnectionFactory connectionFactory = createConnectionFactory();
    ActiveMQPrefetchPolicy prefetchPolicy = new ActiveMQPrefetchPolicy();
    prefetchPolicy.setQueuePrefetch(0);
    connectionFactory.setPrefetchPolicy(prefetchPolicy);
    FileSystemBlobTransferPolicy policy = new FileSystemBlobTransferPolicy();
    policy.setFileSystem(fileSystem);
    policy.setDefaultUploadUrl(BASE_DIR);
    connectionFactory.setBlobTransferPolicy(policy);

    RawMailQueueItemDecoratorFactory mailQueueItemDecoratorFactory = new RawMailQueueItemDecoratorFactory();
    MetricFactory metricFactory = metricTestSystem.getMetricFactory();
    GaugeRegistry gaugeRegistry = metricTestSystem.getSpyGaugeRegistry();
    MailQueueName queueName = BrokerExtension.generateRandomQueueName(broker);
    mailQueue = new ActiveMQCacheableMailQueue(connectionFactory, mailQueueItemDecoratorFactory, queueName, USE_BLOB, metricFactory, gaugeRegistry);
}
 
Example 4
Source File: JmsConfig.java    From c2mon with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public ActiveMQConnectionFactory clientJmsConnectionFactory() {
  ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(properties.getJms().getUrl());
  factory.setConnectionIDPrefix(properties.getJms().getConnectionIDPrefix() + properties.getJms().getClientIdPrefix());
  factory.setTrustAllPackages(true);
  
  ActiveMQPrefetchPolicy prefetchPolicy = new ActiveMQPrefetchPolicy();
  prefetchPolicy.setAll(100);
  factory.setPrefetchPolicy(prefetchPolicy);
  
  return factory;
}
 
Example 5
Source File: AdminJmsConfig.java    From c2mon with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public ActiveMQConnectionFactory adminActiveMQConnectionFactory() {
  String url = properties.getJms().getUrl();

  ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
  connectionFactory.setClientIDPrefix("C2MON-SERVER-CLIENT");
  connectionFactory.setConnectionIDPrefix(properties.getJms().getConnectionIDPrefix() + properties.getJms().getClientIdPrefix());

  ActiveMQPrefetchPolicy prefetchPolicy = new ActiveMQPrefetchPolicy();
  prefetchPolicy.setQueuePrefetch(0);
  connectionFactory.setPrefetchPolicy(prefetchPolicy);
  return connectionFactory;
}
 
Example 6
Source File: SlowConsumerTopicTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 7
Source File: ConcurrentProducerQueueConsumerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
   ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getPublishableConnectString());
   ActiveMQPrefetchPolicy prefetchPolicy = new ActiveMQPrefetchPolicy();
   prefetchPolicy.setAll(1);
   factory.setPrefetchPolicy(prefetchPolicy);

   factory.setDispatchAsync(true);
   return factory;
}
 
Example 8
Source File: TopicDurableConnectStatsTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {

   connectionFactory = new ActiveMQConnectionFactory("vm://" + getName(true));

   ActiveMQPrefetchPolicy prefetchPolicy = new ActiveMQPrefetchPolicy();
   prefetchPolicy.setAll(10);
   connectionFactory.setPrefetchPolicy(prefetchPolicy);

   connectionFactory.setWatchTopicAdvisories(false);
   return connectionFactory;
}
 
Example 9
Source File: ConcurrentProducerDurableConsumerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
   ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getPublishableConnectString());
   ActiveMQPrefetchPolicy prefetchPolicy = new ActiveMQPrefetchPolicy();
   prefetchPolicy.setAll(1);
   factory.setPrefetchPolicy(prefetchPolicy);

   factory.setDispatchAsync(true);
   return factory;
}
 
Example 10
Source File: ActiveMQMailQueueTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setUp(BrokerService broker, MailQueueMetricExtension.MailQueueMetricTestSystem metricTestSystem) {
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?create=false");
    ActiveMQPrefetchPolicy prefetchPolicy = new ActiveMQPrefetchPolicy();
    prefetchPolicy.setQueuePrefetch(0);
    connectionFactory.setPrefetchPolicy(prefetchPolicy);
    RawMailQueueItemDecoratorFactory mailQueueItemDecoratorFactory = new RawMailQueueItemDecoratorFactory();
    MetricFactory metricFactory = metricTestSystem.getMetricFactory();
    GaugeRegistry gaugeRegistry = metricTestSystem.getSpyGaugeRegistry();
    MailQueueName queueName = BrokerExtension.generateRandomQueueName(broker);
    mailQueue = new ActiveMQCacheableMailQueue(connectionFactory, mailQueueItemDecoratorFactory, queueName, !USE_BLOB, metricFactory, gaugeRegistry);
}
 
Example 11
Source File: JMSCacheableMailQueueTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setUp(BrokerService broker, MailQueueMetricExtension.MailQueueMetricTestSystem metricTestSystem) {
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?create=false");
    ActiveMQPrefetchPolicy prefetchPolicy = new ActiveMQPrefetchPolicy();
    prefetchPolicy.setQueuePrefetch(0);
    connectionFactory.setPrefetchPolicy(prefetchPolicy);
    RawMailQueueItemDecoratorFactory mailQueueItemDecoratorFactory = new RawMailQueueItemDecoratorFactory();
    MetricFactory metricFactory = metricTestSystem.getMetricFactory();
    GaugeRegistry gaugeRegistry = metricTestSystem.getSpyGaugeRegistry();
    MailQueueName queueName = BrokerExtension.generateRandomQueueName(broker);
    mailQueue = new JMSCacheableMailQueue(connectionFactory, mailQueueItemDecoratorFactory, queueName, metricFactory, gaugeRegistry);
}
 
Example 12
Source File: AbortSlowConsumer0Test.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testAbortConsumerOnDeadConnection() throws Exception {
   TransportConnector transportConnector = broker.addConnector("tcp://0.0.0.0:0");
   transportConnector.setBrokerService(broker);
   transportConnector.setTaskRunnerFactory(broker.getTaskRunnerFactory());
   transportConnector.start();
   SocketProxy socketProxy = new SocketProxy(transportConnector.getPublishableConnectURI());
   ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(socketProxy.getUrl());
   ActiveMQPrefetchPolicy prefetchPolicy = new ActiveMQPrefetchPolicy();
   prefetchPolicy.setAll(4);
   connectionFactory.setPrefetchPolicy(prefetchPolicy);
   Connection c = connectionFactory.createConnection();
   connections.add(c);
   c.start();
   Session session = c.createSession(false, Session.CLIENT_ACKNOWLEDGE);
   final ActiveMQMessageConsumer messageconsumer = (ActiveMQMessageConsumer) session.createConsumer(destination);
   startProducers(destination, 10);

   messageconsumer.receive(4000).acknowledge();
   assertNotNull(messageconsumer.receive(4000));
   assertNotNull(messageconsumer.receive(4000));
   assertNotNull(messageconsumer.receive(4000));

   // close control command won't get through
   socketProxy.pause();

   ActiveMQDestination amqDest = (ActiveMQDestination) destination;
   ObjectName destinationViewMBean = new ObjectName("org.apache.activemq:destinationType=" +
                                                       (amqDest.isTopic() ? "Topic" : "Queue") + ",destinationName=" + amqDest.getPhysicalName() + ",type=Broker,brokerName=localhost");

   final DestinationViewMBean destView = (DestinationViewMBean) broker.getManagementContext().newProxyInstance(destinationViewMBean, DestinationViewMBean.class, true);

   assertTrue("Consumer gone from broker view", Wait.waitFor(new Wait.Condition() {
      @Override
      public boolean isSatisified() throws Exception {
         LOG.info("DestView {} consumerCount {}", destView, destView.getConsumerCount());
         return 0 == destView.getConsumerCount();
      }
   }));

   socketProxy.goOn();

   assertTrue("consumer was closed", Wait.waitFor(new Wait.Condition() {
      @Override
      public boolean isSatisified() throws Exception {
         boolean closed = false;
         try {
            messageconsumer.receive(400);
         } catch (javax.jms.IllegalStateException expected) {
            closed = expected.toString().contains("closed");
         }
         return closed;
      }
   }));
}
 
Example 13
Source File: TopicProducerFlowControlTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
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;
         }
      }, 5 * 60 * 1000); // give it plenty of time before failing

      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));
   }
 
Example 14
Source File: EmbeddedActiveMQ.java    From james-project with Apache License 2.0 4 votes vote down vote up
private ActiveMQConnectionFactory createActiveMQConnectionFactory(BlobTransferPolicy blobTransferPolicy) {
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://james?create=false");
    connectionFactory.setBlobTransferPolicy(blobTransferPolicy);
    connectionFactory.setPrefetchPolicy(createActiveMQPrefetchPolicy());
    return connectionFactory;
}