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

The following examples show how to use org.apache.activemq.ActiveMQConnectionFactory#setWatchTopicAdvisories() . 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: TopicSubscriptionZeroPrefetchTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {

   brokerService = createBroker();

   ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory("vm://localhost");

   activeMQConnectionFactory.setWatchTopicAdvisories(true);
   connection = activeMQConnectionFactory.createConnection();
   connection.setClientID("ClientID-1");
   session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   destination = new ActiveMQTopic(TOPIC_NAME);
   producer = session.createProducer(destination);

   connection.start();
}
 
Example 2
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 3
Source File: RequestReplyNoAdvisoryNetworkTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private ActiveMQConnectionFactory createConnectionFactory(BrokerService brokerService) throws Exception {
   String target = brokerService.getTransportConnectors().get(0).getPublishableConnectString();
   ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(target);
   factory.setWatchTopicAdvisories(false);
   factory.setConnectionIDPrefix(connectionIdMarker + brokerService.getBrokerName());
   return factory;
}
 
Example 4
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 5
Source File: TopicSubscriptionSlowConsumerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {

   brokerService = createBroker();

   ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory("vm://localhost");

   activeMQConnectionFactory.setWatchTopicAdvisories(true);
   connection = activeMQConnectionFactory.createConnection();
   session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   destination = new ActiveMQTopic(TOPIC_NAME);
   producer = session.createProducer(destination);

   connection.start();
}
 
Example 6
Source File: MessageGroupReconnectDistributionTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
   broker = createBroker();
   broker.start();
   connFactory = new ActiveMQConnectionFactory(connector.getConnectUri() + "?jms.prefetchPolicy.all=200");
   connFactory.setWatchTopicAdvisories(false);
   connection = connFactory.createConnection();
   session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
   producer = session.createProducer(destination);
   connection.start();
}
 
Example 7
Source File: VirtualTopicToFQQNOpenWireTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testAutoVirtualTopicFQQN() throws Exception {
   Connection connection = null;

   SimpleString topic = new SimpleString("VirtualTopic.Orders");
   this.server.getAddressSettingsRepository().getMatch("VirtualTopic.#").setAutoCreateQueues(true);
   this.server.getAddressSettingsRepository().getMatch("VirtualTopic.#").setAutoCreateAddresses(true);

   try {
      ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(urlString);
      activeMQConnectionFactory.setWatchTopicAdvisories(false);
      connection = activeMQConnectionFactory.createConnection();
      connection.start();

      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Destination destination = session.createTopic(topic.toString());

      MessageConsumer messageConsumerA = session.createConsumer(session.createQueue("Consumer.A." + topic.toString()));
      MessageConsumer messageConsumerB = session.createConsumer(session.createQueue("Consumer.B." + topic.toString()));

      MessageProducer producer = session.createProducer(destination);
      TextMessage message = session.createTextMessage("This is a text message");
      producer.send(message);

      TextMessage messageReceivedA = (TextMessage) messageConsumerA.receive(2000);
      TextMessage messageReceivedB = (TextMessage) messageConsumerB.receive(2000);

      assertTrue((messageReceivedA != null && messageReceivedB != null));
      String text = messageReceivedA.getText();
      assertEquals("This is a text message", text);

      messageConsumerA.close();
      messageConsumerB.close();

   } finally {
      if (connection != null) {
         connection.close();
      }
   }
}
 
Example 8
Source File: StoreBasedCursorTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected void start() throws Exception {
   broker.start();
   factory = new ActiveMQConnectionFactory("vm://localhost?jms.alwaysSyncSend=true");
   factory.setWatchTopicAdvisories(false);
   connection = factory.createConnection();
   connection.start();
   session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   queue = session.createQueue("QUEUE." + this.getClass().getName());
}
 
Example 9
Source File: DurableSubscriptionOfflineTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Override
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
   ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://" + getName(true));
   connectionFactory.setWatchTopicAdvisories(false);
   return connectionFactory;
}
 
Example 10
Source File: DurableSubsOfflineSelectorConcurrentConsumeIndexUseTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Override
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
   ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://" + getName(true));
   connectionFactory.setWatchTopicAdvisories(false);
   return connectionFactory;
}
 
Example 11
Source File: DurableSubscriptionOfflineTestBase.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
   ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://" + getName(true));
   connectionFactory.setWatchTopicAdvisories(false);
   return connectionFactory;
}
 
Example 12
Source File: FailoverPrefetchZeroTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
@BMRules(
   rules = {@BMRule(
      name = "set no return response and stop the broker",
      targetClass = "org.apache.activemq.artemis.core.protocol.openwire.OpenWireConnection$CommandProcessor",
      targetMethod = "processMessagePull",
      targetLocation = "ENTRY",
      action = "org.apache.activemq.transport.failover.FailoverPrefetchZeroTest.holdResponseAndStopBroker($0)")})
public void testPrefetchZeroConsumerThroughRestart() throws Exception {
   broker = createBroker();
   broker.start();
   doByteman.set(true);

   ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("failover:(" + url + ")");
   cf.setWatchTopicAdvisories(false);

   final ActiveMQConnection connection = (ActiveMQConnection) cf.createConnection();
   connection.start();

   final Session consumerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   final Queue destination = consumerSession.createQueue(QUEUE_NAME + "?consumer.prefetchSize=" + prefetch);

   final MessageConsumer consumer = consumerSession.createConsumer(destination);
   produceMessage(consumerSession, destination, 1);

   final CountDownLatch receiveDone = new CountDownLatch(1);
   final Vector<Message> received = new Vector<>();
   new Thread() {
      @Override
      public void run() {
         try {
            LOG.info("receive one...");
            Message msg = consumer.receive(30000);
            if (msg != null) {
               received.add(msg);
            }
            receiveDone.countDown();
            LOG.info("done receive");
         } catch (Exception e) {
            e.printStackTrace();
         }
      }
   }.start();

   // will be stopped by the plugin
   assertTrue("pull completed on broker", pullDone.await(30, TimeUnit.SECONDS));
   brokerStopLatch.await();
   doByteman.set(false);
   broker = createBroker();
   broker.start();

   assertTrue("receive completed through failover", receiveDone.await(30, TimeUnit.SECONDS));

   assertTrue("we got our message:", !received.isEmpty());

   connection.close();
}
 
Example 13
Source File: FQQNOpenWireTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testVirtualTopicFQQNAutoCreateQWithExistingAddressWithAnyCastDefault() throws Exception {
   Connection exConn = null;

   SimpleString topic = new SimpleString("VirtualTopic.Orders");
   SimpleString subscriptionQ = new SimpleString("Consumer.A");

   // defaults are false via test setUp
   this.server.addAddressInfo(new AddressInfo(topic, RoutingType.MULTICAST));
   this.server.getAddressSettingsRepository().getMatch("VirtualTopic.#").setAutoCreateQueues(true);
   this.server.getAddressSettingsRepository().getMatch("VirtualTopic.#").setAutoCreateAddresses(false);

   // set default to anycast which would fail if used in queue auto creation
   this.server.getAddressSettingsRepository().getMatch("VirtualTopic.#").setDefaultAddressRoutingType(RoutingType.ANYCAST);

   try {
      ActiveMQConnectionFactory exFact = new ActiveMQConnectionFactory();
      exFact.setWatchTopicAdvisories(false);
      exConn = exFact.createConnection();
      exConn.start();

      Session session = exConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Destination destination = session.createTopic(topic.toString());
      MessageProducer producer = session.createProducer(destination);

      Destination destinationFQN = session.createQueue(CompositeAddress.toFullyQualified(topic, subscriptionQ).toString());

      MessageConsumer messageConsumerA = session.createConsumer(destinationFQN);
      MessageConsumer messageConsumerB = session.createConsumer(destinationFQN);

      TextMessage message = session.createTextMessage("This is a text message");
      producer.send(message);

      // only one consumer should get the message
      TextMessage messageReceivedA = (TextMessage) messageConsumerA.receive(2000);
      TextMessage messageReceivedB = (TextMessage) messageConsumerB.receive(2000);

      assertTrue((messageReceivedA == null || messageReceivedB == null));
      String text = messageReceivedA != null ? messageReceivedA.getText() : messageReceivedB.getText();
      assertEquals("This is a text message", text);

      messageConsumerA.close();
      messageConsumerB.close();

   } finally {
      if (exConn != null) {
         exConn.close();
      }
   }
}
 
Example 14
Source File: FQQNOpenWireTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testVirtualTopicFQQNConsumerAutoCreateQAndAddress() throws Exception {
   Connection exConn = null;

   SimpleString topic = new SimpleString("VirtualTopic.Orders");
   SimpleString subscriptionQ = new SimpleString("Consumer.A");

   // defaults are false via test setUp
   this.server.getAddressSettingsRepository().getMatch("VirtualTopic.#").setAutoCreateQueues(true);
   this.server.getAddressSettingsRepository().getMatch("VirtualTopic.#").setAutoCreateAddresses(true);

   try {
      ActiveMQConnectionFactory exFact = new ActiveMQConnectionFactory();
      exFact.setWatchTopicAdvisories(false);
      exConn = exFact.createConnection();
      exConn.start();

      Session session = exConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Destination destination = session.createTopic(topic.toString());
      Destination destinationFQN = session.createQueue(CompositeAddress.toFullyQualified(topic, subscriptionQ).toString());

      MessageConsumer messageConsumerA = session.createConsumer(destinationFQN);
      MessageConsumer messageConsumerB = session.createConsumer(destinationFQN);

      MessageProducer producer = session.createProducer(destination);
      TextMessage message = session.createTextMessage("This is a text message");
      producer.send(message);

      // only one consumer should get the message
      TextMessage messageReceivedA = (TextMessage) messageConsumerA.receive(2000);
      TextMessage messageReceivedB = (TextMessage) messageConsumerB.receive(2000);

      assertTrue((messageReceivedA == null || messageReceivedB == null));
      String text = messageReceivedA != null ? messageReceivedA.getText() : messageReceivedB.getText();
      assertEquals("This is a text message", text);

      messageConsumerA.close();
      messageConsumerB.close();

   } finally {
      if (exConn != null) {
         exConn.close();
      }
   }
}
 
Example 15
Source File: FQQNOpenWireTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testVirtualTopicFQQNAutoCreateQAndAddress() throws Exception {
   Connection exConn = null;

   SimpleString topic = new SimpleString("VirtualTopic.Orders");
   SimpleString subscriptionQ = new SimpleString("Consumer.A");

   // defaults are false via test setUp
   this.server.getAddressSettingsRepository().getMatch("VirtualTopic.#").setAutoCreateQueues(true);
   this.server.getAddressSettingsRepository().getMatch("VirtualTopic.#").setAutoCreateAddresses(true);

   try {
      ActiveMQConnectionFactory exFact = new ActiveMQConnectionFactory();
      exFact.setWatchTopicAdvisories(false);
      exConn = exFact.createConnection();
      exConn.start();

      Session session = exConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Destination destination = session.createTopic(topic.toString());
      MessageProducer producer = session.createProducer(destination);

      Destination destinationFQN = session.createQueue(CompositeAddress.toFullyQualified(topic, subscriptionQ).toString());

      MessageConsumer messageConsumerA = session.createConsumer(destinationFQN);
      MessageConsumer messageConsumerB = session.createConsumer(destinationFQN);

      TextMessage message = session.createTextMessage("This is a text message");
      producer.send(message);

      // only one consumer should get the message
      TextMessage messageReceivedA = (TextMessage) messageConsumerA.receive(2000);
      TextMessage messageReceivedB = (TextMessage) messageConsumerB.receive(2000);

      assertTrue((messageReceivedA == null || messageReceivedB == null));
      String text = messageReceivedA != null ? messageReceivedA.getText() : messageReceivedB.getText();
      assertEquals("This is a text message", text);

      messageConsumerA.close();
      messageConsumerB.close();

   } finally {
      if (exConn != null) {
         exConn.close();
      }
   }
}
 
Example 16
Source File: FQQNOpenWireTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testVirtualTopicFQQNAutoCreateQueue() throws Exception {
   Connection exConn = null;

   SimpleString topic = new SimpleString("VirtualTopic.Orders");
   SimpleString subscriptionQ = new SimpleString("Consumer.A");

   // defaults are false via test setUp
   this.server.addAddressInfo(new AddressInfo(topic, RoutingType.MULTICAST));
   this.server.getAddressSettingsRepository().getMatch("VirtualTopic.#").setAutoCreateQueues(true);

   try {
      ActiveMQConnectionFactory exFact = new ActiveMQConnectionFactory();
      exFact.setWatchTopicAdvisories(false);
      exConn = exFact.createConnection();
      exConn.start();

      Session session = exConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Destination destination = session.createTopic(topic.toString());
      MessageProducer producer = session.createProducer(destination);

      Destination destinationFQN = session.createQueue(CompositeAddress.toFullyQualified(topic, subscriptionQ).toString());

      MessageConsumer messageConsumerA = session.createConsumer(destinationFQN);
      MessageConsumer messageConsumerB = session.createConsumer(destinationFQN);

      TextMessage message = session.createTextMessage("This is a text message");
      producer.send(message);

      // only one consumer should get the message
      TextMessage messageReceivedA = (TextMessage) messageConsumerA.receive(2000);
      TextMessage messageReceivedB = (TextMessage) messageConsumerB.receive(2000);

      assertTrue((messageReceivedA == null || messageReceivedB == null));
      String text = messageReceivedA != null ? messageReceivedA.getText() : messageReceivedB.getText();
      assertEquals("This is a text message", text);

      messageConsumerA.close();
      messageConsumerB.close();

   } finally {
      if (exConn != null) {
         exConn.close();
      }
   }
}
 
Example 17
Source File: FQQNOpenWireTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testVirtualTopicFQQN() throws Exception {
   Connection exConn = null;

   SimpleString topic = new SimpleString("VirtualTopic.Orders");
   SimpleString subscriptionQ = new SimpleString("Consumer.A");

   this.server.addAddressInfo(new AddressInfo(topic, RoutingType.MULTICAST));
   this.server.createQueue(new QueueConfiguration(subscriptionQ).setAddress(topic));

   try {
      ActiveMQConnectionFactory exFact = new ActiveMQConnectionFactory();
      exFact.setWatchTopicAdvisories(false);
      exConn = exFact.createConnection();
      exConn.start();

      Session session = exConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Destination destination = session.createTopic(topic.toString());
      MessageProducer producer = session.createProducer(destination);

      Destination destinationFQN = session.createQueue(CompositeAddress.toFullyQualified(topic, subscriptionQ).toString());
      MessageConsumer messageConsumerA = session.createConsumer(destinationFQN);
      MessageConsumer messageConsumerB = session.createConsumer(destinationFQN);

      TextMessage message = session.createTextMessage("This is a text message");
      producer.send(message);

      // only one consumer should get the message
      TextMessage messageReceivedA = (TextMessage) messageConsumerA.receive(2000);
      TextMessage messageReceivedB = (TextMessage) messageConsumerB.receive(2000);

      assertTrue((messageReceivedA == null || messageReceivedB == null));
      String text = messageReceivedA != null ? messageReceivedA.getText() : messageReceivedB.getText();
      assertEquals("This is a text message", text);

      messageConsumerA.close();
      messageConsumerB.close();

   } finally {
      if (exConn != null) {
         exConn.close();
      }
   }
}
 
Example 18
Source File: VirtualTopicToFQQNOpenWireTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testAutoVirtualTopicWildcardStarFQQN() throws Exception {
   Connection connection = null;

   SimpleString topicA = new SimpleString("VirtualTopic.Orders.A");
   SimpleString topicB = new SimpleString("VirtualTopic.Orders.B");
   SimpleString topic = new SimpleString("VirtualTopic.Orders.*");

   this.server.getAddressSettingsRepository().getMatch("VirtualTopic.#").setAutoCreateQueues(true);
   this.server.getAddressSettingsRepository().getMatch("VirtualTopic.#").setAutoCreateAddresses(true);

   try {
      ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(urlString);
      activeMQConnectionFactory.setWatchTopicAdvisories(false);
      connection = activeMQConnectionFactory.createConnection();
      connection.start();

      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Destination destination = session.createTopic(topicA.toString() + "," + topicB.toString());

      MessageConsumer messageConsumerA = session.createConsumer(session.createQueue("Consumer.A." + topic.toString()));

      MessageProducer producer = session.createProducer(destination);
      TextMessage message = session.createTextMessage("This is a text message");
      producer.send(message);

      TextMessage messageReceivedA = (TextMessage) messageConsumerA.receive(2000);
      TextMessage messageReceivedB = (TextMessage) messageConsumerA.receive(2000);

      assertTrue((messageReceivedA != null && messageReceivedB != null));
      String text = messageReceivedA.getText();
      assertEquals("This is a text message", text);

      messageConsumerA.close();

   } finally {
      if (connection != null) {
         connection.close();
      }
   }
}
 
Example 19
Source File: VirtualTopicToFQQNOpenWireTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testAutoVirtualTopicWildcardFQQN() throws Exception {
   Connection connection = null;

   SimpleString topicA = new SimpleString("VirtualTopic.Orders.A");
   SimpleString topicB = new SimpleString("VirtualTopic.Orders.B");
   SimpleString topic = new SimpleString("VirtualTopic.Orders.>");

   this.server.getAddressSettingsRepository().getMatch("VirtualTopic.#").setAutoCreateQueues(true);
   this.server.getAddressSettingsRepository().getMatch("VirtualTopic.#").setAutoCreateAddresses(true);

   try {
      ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(urlString);
      activeMQConnectionFactory.setWatchTopicAdvisories(false);
      connection = activeMQConnectionFactory.createConnection();
      connection.start();

      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Destination destination = session.createTopic(topicA.toString() + "," + topicB.toString());

      MessageConsumer messageConsumerA = session.createConsumer(session.createQueue("Consumer.A." + topic.toString()));
     // MessageConsumer messageConsumerB = session.createConsumer(session.createQueue("Consumer.B." + topic.toString()));

      MessageProducer producer = session.createProducer(destination);
      TextMessage message = session.createTextMessage("This is a text message");
      producer.send(message);

      TextMessage messageReceivedA = (TextMessage) messageConsumerA.receive(2000);
      TextMessage messageReceivedB = (TextMessage) messageConsumerA.receive(2000);

      assertTrue((messageReceivedA != null && messageReceivedB != null));
      String text = messageReceivedA.getText();
      assertEquals("This is a text message", text);

      messageConsumerA.close();

   } finally {
      if (connection != null) {
         connection.close();
      }
   }
}
 
Example 20
Source File: DurableSubsOfflineSelectorIndexUseTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Override
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
   ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://" + getName(true));
   connectionFactory.setWatchTopicAdvisories(false);
   return connectionFactory;
}