Java Code Examples for org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory#setConsumerWindowSize()

The following examples show how to use org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory#setConsumerWindowSize() . 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: JMSServerManagerImpl.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
/**
 * @param cfConfig
 * @return
 * @throws ActiveMQException
 */
protected ActiveMQConnectionFactory internalCreateCFPOJO(final ConnectionFactoryConfiguration cfConfig) throws ActiveMQException {
   ActiveMQConnectionFactory cf;
   if (cfConfig.getDiscoveryGroupName() != null) {
      DiscoveryGroupConfiguration groupConfig = server.getConfiguration().getDiscoveryGroupConfigurations().get(cfConfig.getDiscoveryGroupName());

      if (groupConfig == null) {
         throw ActiveMQJMSServerBundle.BUNDLE.discoveryGroupDoesntExist(cfConfig.getDiscoveryGroupName());
      }

      if (cfConfig.isHA()) {
         cf = ActiveMQJMSClient.createConnectionFactoryWithHA(groupConfig, cfConfig.getFactoryType());
      } else {
         cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(groupConfig, cfConfig.getFactoryType());
      }
   } else {
      if (cfConfig.getConnectorNames() == null || cfConfig.getConnectorNames().size() == 0) {
         throw ActiveMQJMSServerBundle.BUNDLE.noConnectorNameOnCF();
      }

      TransportConfiguration[] configs = new TransportConfiguration[cfConfig.getConnectorNames().size()];

      int count = 0;
      for (String name : cfConfig.getConnectorNames()) {
         TransportConfiguration connector = server.getConfiguration().getConnectorConfigurations().get(name);
         if (connector == null) {
            throw ActiveMQJMSServerBundle.BUNDLE.noConnectorNameConfiguredOnCF(name);
         }
         correctInvalidNettyConnectorHost(connector);
         configs[count++] = connector;
      }

      if (cfConfig.isHA()) {
         cf = ActiveMQJMSClient.createConnectionFactoryWithHA(cfConfig.getFactoryType(), configs);
      } else {
         cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(cfConfig.getFactoryType(), configs);
      }
   }

   cf.setClientID(cfConfig.getClientID());
   cf.setClientFailureCheckPeriod(cfConfig.getClientFailureCheckPeriod());
   cf.setConnectionTTL(cfConfig.getConnectionTTL());
   cf.setCallTimeout(cfConfig.getCallTimeout());
   cf.setCallFailoverTimeout(cfConfig.getCallFailoverTimeout());
   cf.setCacheLargeMessagesClient(cfConfig.isCacheLargeMessagesClient());
   cf.setMinLargeMessageSize(cfConfig.getMinLargeMessageSize());
   cf.setConsumerWindowSize(cfConfig.getConsumerWindowSize());
   cf.setConsumerMaxRate(cfConfig.getConsumerMaxRate());
   cf.setConfirmationWindowSize(cfConfig.getConfirmationWindowSize());
   cf.setProducerWindowSize(cfConfig.getProducerWindowSize());
   cf.setProducerMaxRate(cfConfig.getProducerMaxRate());
   cf.setBlockOnAcknowledge(cfConfig.isBlockOnAcknowledge());
   cf.setBlockOnDurableSend(cfConfig.isBlockOnDurableSend());
   cf.setBlockOnNonDurableSend(cfConfig.isBlockOnNonDurableSend());
   cf.setAutoGroup(cfConfig.isAutoGroup());
   cf.setPreAcknowledge(cfConfig.isPreAcknowledge());
   cf.setConnectionLoadBalancingPolicyClassName(cfConfig.getLoadBalancingPolicyClassName());
   cf.setTransactionBatchSize(cfConfig.getTransactionBatchSize());
   cf.setDupsOKBatchSize(cfConfig.getDupsOKBatchSize());
   cf.setUseGlobalPools(cfConfig.isUseGlobalPools());
   cf.setScheduledThreadPoolMaxSize(cfConfig.getScheduledThreadPoolMaxSize());
   cf.setThreadPoolMaxSize(cfConfig.getThreadPoolMaxSize());
   cf.setRetryInterval(cfConfig.getRetryInterval());
   cf.setRetryIntervalMultiplier(cfConfig.getRetryIntervalMultiplier());
   cf.setMaxRetryInterval(cfConfig.getMaxRetryInterval());
   cf.setReconnectAttempts(cfConfig.getReconnectAttempts());
   cf.setFailoverOnInitialConnection(cfConfig.isFailoverOnInitialConnection());
   cf.setCompressLargeMessage(cfConfig.isCompressLargeMessages());
   cf.setGroupID(cfConfig.getGroupID());
   cf.setProtocolManagerFactoryStr(cfConfig.getProtocolManagerFactoryStr());
   cf.setDeserializationBlackList(cfConfig.getDeserializationBlackList());
   cf.setDeserializationWhiteList(cfConfig.getDeserializationWhiteList());
   cf.setInitialMessagePacketSize(cfConfig.getInitialMessagePacketSize());
   cf.setEnable1xPrefixes(cfConfig.isEnable1xPrefixes());
   cf.setEnableSharedClientID(cfConfig.isEnableSharedClientID());
   cf.setUseTopologyForLoadBalancing(cfConfig.getUseTopologyForLoadBalancing());

   return cf;
}
 
Example 2
Source File: ActiveMQConnectionFactoryTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testGettersAndSetters() {
   ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, liveTC);

   long clientFailureCheckPeriod = RandomUtil.randomPositiveLong();
   long connectionTTL = RandomUtil.randomPositiveLong();
   long callTimeout = RandomUtil.randomPositiveLong();
   int minLargeMessageSize = RandomUtil.randomPositiveInt();
   int consumerWindowSize = RandomUtil.randomPositiveInt();
   int consumerMaxRate = RandomUtil.randomPositiveInt();
   int confirmationWindowSize = RandomUtil.randomPositiveInt();
   int producerMaxRate = RandomUtil.randomPositiveInt();
   boolean blockOnAcknowledge = RandomUtil.randomBoolean();
   boolean blockOnDurableSend = RandomUtil.randomBoolean();
   boolean blockOnNonDurableSend = RandomUtil.randomBoolean();
   boolean autoGroup = RandomUtil.randomBoolean();
   boolean preAcknowledge = RandomUtil.randomBoolean();
   String loadBalancingPolicyClassName = RandomUtil.randomString();
   boolean useGlobalPools = RandomUtil.randomBoolean();
   int scheduledThreadPoolMaxSize = RandomUtil.randomPositiveInt();
   int threadPoolMaxSize = RandomUtil.randomPositiveInt();
   long retryInterval = RandomUtil.randomPositiveLong();
   double retryIntervalMultiplier = RandomUtil.randomDouble();
   int reconnectAttempts = RandomUtil.randomPositiveInt();
   cf.setClientFailureCheckPeriod(clientFailureCheckPeriod);
   cf.setConnectionTTL(connectionTTL);
   cf.setCallTimeout(callTimeout);
   cf.setMinLargeMessageSize(minLargeMessageSize);
   cf.setConsumerWindowSize(consumerWindowSize);
   cf.setConsumerMaxRate(consumerMaxRate);
   cf.setConfirmationWindowSize(confirmationWindowSize);
   cf.setProducerMaxRate(producerMaxRate);
   cf.setBlockOnAcknowledge(blockOnAcknowledge);
   cf.setBlockOnDurableSend(blockOnDurableSend);
   cf.setBlockOnNonDurableSend(blockOnNonDurableSend);
   cf.setAutoGroup(autoGroup);
   cf.setPreAcknowledge(preAcknowledge);
   cf.setConnectionLoadBalancingPolicyClassName(loadBalancingPolicyClassName);
   cf.setUseGlobalPools(useGlobalPools);
   cf.setScheduledThreadPoolMaxSize(scheduledThreadPoolMaxSize);
   cf.setThreadPoolMaxSize(threadPoolMaxSize);
   cf.setRetryInterval(retryInterval);
   cf.setRetryIntervalMultiplier(retryIntervalMultiplier);
   cf.setReconnectAttempts(reconnectAttempts);
   Assert.assertEquals(clientFailureCheckPeriod, cf.getClientFailureCheckPeriod());
   Assert.assertEquals(connectionTTL, cf.getConnectionTTL());
   Assert.assertEquals(callTimeout, cf.getCallTimeout());
   Assert.assertEquals(minLargeMessageSize, cf.getMinLargeMessageSize());
   Assert.assertEquals(consumerWindowSize, cf.getConsumerWindowSize());
   Assert.assertEquals(consumerMaxRate, cf.getConsumerMaxRate());
   Assert.assertEquals(confirmationWindowSize, cf.getConfirmationWindowSize());
   Assert.assertEquals(producerMaxRate, cf.getProducerMaxRate());
   Assert.assertEquals(blockOnAcknowledge, cf.isBlockOnAcknowledge());
   Assert.assertEquals(blockOnDurableSend, cf.isBlockOnDurableSend());
   Assert.assertEquals(blockOnNonDurableSend, cf.isBlockOnNonDurableSend());
   Assert.assertEquals(autoGroup, cf.isAutoGroup());
   Assert.assertEquals(preAcknowledge, cf.isPreAcknowledge());
   Assert.assertEquals(loadBalancingPolicyClassName, cf.getConnectionLoadBalancingPolicyClassName());
   Assert.assertEquals(useGlobalPools, cf.isUseGlobalPools());
   Assert.assertEquals(scheduledThreadPoolMaxSize, cf.getScheduledThreadPoolMaxSize());
   Assert.assertEquals(threadPoolMaxSize, cf.getThreadPoolMaxSize());
   Assert.assertEquals(retryInterval, cf.getRetryInterval());
   Assert.assertEquals(retryIntervalMultiplier, cf.getRetryIntervalMultiplier(), 0.0001);
   Assert.assertEquals(reconnectAttempts, cf.getReconnectAttempts());

   cf.close();
}
 
Example 3
Source File: LVQTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testLastValueQueueUsingAddressQueueParameters() throws Exception {
   ActiveMQConnectionFactory fact = (ActiveMQConnectionFactory) getCF();

   //Set the consumer window size to 0 to not buffer any messages client side.
   fact.setConsumerWindowSize(0);
   Connection connection = fact.createConnection();

   try {

      Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);

      Queue queue = session.createQueue("random?last-value=true");
      assertEquals("random", queue.getQueueName());

      ActiveMQDestination a = (ActiveMQDestination) queue;
      assertTrue(a.getQueueAttributes().getLastValue());
      assertTrue(a.getQueueConfiguration().isLastValue());

      MessageProducer producer = session.createProducer(queue);
      MessageConsumer consumer1 = session.createConsumer(queue);

      connection.start();
      for (int j = 0; j < 100; j++) {
         TextMessage message = session.createTextMessage();

         message.setText("Message" + j);
         message.setStringProperty(Message.HDR_LAST_VALUE_NAME.toString(), "key");
         producer.send(message);
      }

      //Last message only should go to the consumer
      TextMessage tm = (TextMessage) consumer1.receive(10000);

      assertNotNull(tm);

      assertEquals("Message99", tm.getText());

   } finally {
      connection.close();
   }
}
 
Example 4
Source File: LVQTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testLastValueKeyUsingAddressQueueParameters() throws Exception {
   ActiveMQConnectionFactory fact = (ActiveMQConnectionFactory) getCF();

   //Set the consumer window size to 0 to not buffer any messages client side.
   fact.setConsumerWindowSize(0);
   Connection connection = fact.createConnection();

   try {

      Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);

      Queue queue = session.createQueue("random?last-value-key=reuters_code");
      assertEquals("random", queue.getQueueName());

      ActiveMQDestination a = (ActiveMQDestination) queue;
      assertEquals("reuters_code", a.getQueueAttributes().getLastValueKey().toString());
      assertEquals("reuters_code", a.getQueueConfiguration().getLastValueKey().toString());

      MessageProducer producer = session.createProducer(queue);
      MessageConsumer consumer1 = session.createConsumer(queue);

      connection.start();
      for (int j = 0; j < 100; j++) {
         TextMessage message = session.createTextMessage();

         message.setText("Message" + j);
         message.setStringProperty("reuters_code", "key");
         producer.send(message);
      }

      //Last message only should go to the consumer
      TextMessage tm = (TextMessage) consumer1.receive(10000);

      assertNotNull(tm);

      assertEquals("Message99", tm.getText());

   } finally {
      connection.close();
   }
}
 
Example 5
Source File: LVQTest.java    From activemq-artemis with Apache License 2.0 2 votes vote down vote up
@Test
public void testLastValueQueueTopicConsumerUsingAddressQueueParameters() throws Exception {
   ActiveMQConnectionFactory fact = (ActiveMQConnectionFactory) getCF();

   //Set the consumer window size to 0 to not buffer any messages client side.
   fact.setConsumerWindowSize(0);
   Connection connection = fact.createConnection();

   try {

      Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);

      Topic topic = session.createTopic("topic?last-value=true");
      assertEquals("topic", topic.getTopicName());

      ActiveMQDestination a = (ActiveMQDestination) topic;
      assertTrue(a.getQueueAttributes().getLastValue());
      assertTrue(a.getQueueConfiguration().isLastValue());

      MessageProducer producer = session.createProducer(topic);
      MessageConsumer consumer1 = session.createConsumer(topic);
      MessageConsumer consumer2 = session.createConsumer(topic);

      connection.start();
      for (int j = 0; j < 100; j++) {
         TextMessage message = session.createTextMessage();

         message.setText("Message" + j);
         message.setStringProperty(Message.HDR_LAST_VALUE_NAME.toString(), "key");
         producer.send(message);
      }



      //Last message only should go to the consumer.
      TextMessage tm = (TextMessage) consumer1.receive(10000);

      assertNotNull(tm);

      assertEquals("Message99", tm.getText());

      //Last message only should go to the other consumer as well.
      TextMessage tm2 = (TextMessage) consumer2.receive(10000);

      assertNotNull(tm2);

      assertEquals("Message99", tm2.getText());

   } finally {
      connection.close();
   }
}
 
Example 6
Source File: LVQTest.java    From activemq-artemis with Apache License 2.0 2 votes vote down vote up
@Test
public void testLastValueKeyTopicConsumerUsingAddressQueueParameters() throws Exception {
   ActiveMQConnectionFactory fact = (ActiveMQConnectionFactory) getCF();

   //Set the consumer window size to 0 to not buffer any messages client side.
   fact.setConsumerWindowSize(0);
   Connection connection = fact.createConnection();

   try {

      Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);

      Topic topic = session.createTopic("topic?last-value-key=reuters_code");
      assertEquals("topic", topic.getTopicName());

      ActiveMQDestination a = (ActiveMQDestination) topic;
      assertEquals("reuters_code", a.getQueueAttributes().getLastValueKey().toString());
      assertEquals("reuters_code", a.getQueueConfiguration().getLastValueKey().toString());

      MessageProducer producer = session.createProducer(topic);
      MessageConsumer consumer1 = session.createConsumer(topic);
      MessageConsumer consumer2 = session.createConsumer(topic);

      connection.start();
      for (int j = 0; j < 100; j++) {
         TextMessage message = session.createTextMessage();

         message.setText("Message" + j);
         message.setStringProperty("reuters_code", "key");
         producer.send(message);
      }



      //Last message only should go to the consumer.
      TextMessage tm = (TextMessage) consumer1.receive(10000);

      assertNotNull(tm);

      assertEquals("Message99", tm.getText());

      //Last message only should go to the other consumer as well.
      TextMessage tm2 = (TextMessage) consumer2.receive(10000);

      assertNotNull(tm2);

      assertEquals("Message99", tm2.getText());

   } finally {
      connection.close();
   }
}