Java Code Examples for org.apache.activemq.artemis.api.core.RoutingType#MULTICAST

The following examples show how to use org.apache.activemq.artemis.api.core.RoutingType#MULTICAST . 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: AMQPMessage.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public final RoutingType getRoutingType() {
   ensureMessageDataScanned();
   Object routingType = getMessageAnnotation(AMQPMessageSupport.ROUTING_TYPE);

   if (routingType != null) {
      return RoutingType.getType(((Number) routingType).byteValue());
   } else {
      routingType = getMessageAnnotation(AMQPMessageSupport.JMS_DEST_TYPE_MSG_ANNOTATION);
      if (routingType != null) {
         if (AMQPMessageSupport.QUEUE_TYPE == ((Number) routingType).byteValue() || AMQPMessageSupport.TEMP_QUEUE_TYPE == ((Number) routingType).byteValue()) {
            return RoutingType.ANYCAST;
         } else if (AMQPMessageSupport.TOPIC_TYPE == ((Number) routingType).byteValue() || AMQPMessageSupport.TEMP_TOPIC_TYPE == ((Number) routingType).byteValue()) {
            return RoutingType.MULTICAST;
         }
      } else {
         return null;
      }

      return null;
   }
}
 
Example 2
Source File: ProtonServerReceiverContext.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private RoutingType getRoutingType(Symbol[] symbols, SimpleString address) {
   if (symbols != null) {
      for (Symbol symbol : symbols) {
         if (AmqpSupport.TEMP_TOPIC_CAPABILITY.equals(symbol) || AmqpSupport.TOPIC_CAPABILITY.equals(symbol)) {
            return RoutingType.MULTICAST;
         } else if (AmqpSupport.TEMP_QUEUE_CAPABILITY.equals(symbol) || AmqpSupport.QUEUE_CAPABILITY.equals(symbol)) {
            return RoutingType.ANYCAST;
         }
      }
   }
   final AddressInfo addressInfo = sessionSPI.getAddress(address);
   if (addressInfo != null && !addressInfo.getRoutingTypes().isEmpty()) {
      if (addressInfo.getRoutingTypes().size() == 1 && addressInfo.getRoutingType() == RoutingType.MULTICAST) {
         return RoutingType.MULTICAST;
      }
   }
   RoutingType defaultRoutingType = sessionSPI.getDefaultRoutingType(address);
   defaultRoutingType = defaultRoutingType == null ? ActiveMQDefaultConfiguration.getDefaultRoutingType() : defaultRoutingType;
   return defaultRoutingType;
}
 
Example 3
Source File: QueueImpl.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Deprecated
public QueueImpl(final long id,
                 final SimpleString address,
                 final SimpleString name,
                 final Filter filter,
                 final PagingStore pagingStore,
                 final PageSubscription pageSubscription,
                 final SimpleString user,
                 final boolean durable,
                 final boolean temporary,
                 final boolean autoCreated,
                 final ScheduledExecutorService scheduledExecutor,
                 final PostOffice postOffice,
                 final StorageManager storageManager,
                 final HierarchicalRepository<AddressSettings> addressSettingsRepository,
                 final ArtemisExecutor executor,
                 final ActiveMQServer server,
                 final QueueFactory factory) {
   this(id, address, name, filter, pagingStore, pageSubscription, user, durable, temporary, autoCreated, RoutingType.MULTICAST, null, null, scheduledExecutor, postOffice, storageManager, addressSettingsRepository, executor, server, factory);
}
 
Example 4
Source File: CompositeDestinationTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
@Before
public void setUp() throws Exception {
   super.setUp();
   AddressInfo addressInfo = new AddressInfo(new SimpleString("p.IN"), RoutingType.MULTICAST);
   this.server.addAddressInfo(addressInfo);
   addressInfo = new AddressInfo(new SimpleString("q.IN"), RoutingType.MULTICAST);
   this.server.addAddressInfo(addressInfo);
}
 
Example 5
Source File: AmqpSenderRoutingTypeTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testAMQPSenderHonourRoutingTypeOfExistingAddress() throws Exception {
   RoutingType routingType = server.getConfiguration().getAddressesSettings().get("#").getDefaultAddressRoutingType();
   Assert.assertEquals(RoutingType.ANYCAST, routingType);
   try (ActiveMQConnection coreConnection = (ActiveMQConnection) createCoreConnection();
        ClientSession clientSession = coreConnection.getSessionFactory().createSession()) {
      RoutingType addressRoutingType = RoutingType.MULTICAST;
      SimpleString address = SimpleString.toSimpleString("myTopic_" + UUID.randomUUID().toString());
      clientSession.createAddress(address, addressRoutingType, false);
      ClientSession.AddressQuery addressQuery = clientSession.addressQuery(address);
      Assert.assertTrue(addressQuery.isExists());
      Assert.assertTrue(addressQuery.getQueueNames().isEmpty());
      AmqpClient client = createAmqpClient(guestUser, guestPass);
      AmqpConnection connection = addConnection(client.connect());
      AmqpSession session = connection.createSession();
      AmqpSender sender = session.createSender(address.toString());
      try {
         ClientSession.QueueQuery queueQuery = clientSession.queueQuery(address);
         Assert.assertFalse(queueQuery.isExists());
         Assert.assertEquals(addressRoutingType, queueQuery.getRoutingType());
      } finally {
         sender.close();
         session.close();
         connection.close();
      }
   }

}
 
Example 6
Source File: QueueCommandTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdateCoreQueue() throws Exception {
   final String queueName = "updateQueue";
   final SimpleString queueNameString = new SimpleString(queueName);
   final String addressName = "address";
   final SimpleString addressSimpleString = new SimpleString(addressName);
   final int oldMaxConsumers = -1;
   final RoutingType oldRoutingType = RoutingType.MULTICAST;
   final boolean oldPurgeOnNoConsumers = false;
   final AddressInfo addressInfo = new AddressInfo(addressSimpleString, EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST));
   server.addAddressInfo(addressInfo);
   server.createQueue(new QueueConfiguration(queueNameString).setAddress(addressSimpleString).setRoutingType(oldRoutingType).setMaxConsumers(oldMaxConsumers).setPurgeOnNoConsumers(oldPurgeOnNoConsumers).setAutoCreateAddress(false));

   final int newMaxConsumers = 1;
   final RoutingType newRoutingType = RoutingType.ANYCAST;
   final boolean newPurgeOnNoConsumers = true;
   final UpdateQueue updateQueue = new UpdateQueue();
   updateQueue.setName(queueName);
   updateQueue.setPurgeOnNoConsumers(newPurgeOnNoConsumers);
   updateQueue.setAnycast(true);
   updateQueue.setMulticast(false);
   updateQueue.setMaxConsumers(newMaxConsumers);
   updateQueue.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error)));

   checkExecutionPassed(updateQueue);

   final QueueQueryResult queueQueryResult = server.queueQuery(queueNameString);
   assertEquals("maxConsumers", newMaxConsumers, queueQueryResult.getMaxConsumers());
   assertEquals("routingType", newRoutingType, queueQueryResult.getRoutingType());
   assertTrue("purgeOnNoConsumers", newPurgeOnNoConsumers == queueQueryResult.isPurgeOnNoConsumers());
}
 
Example 7
Source File: QueueCommandTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdateCoreQueueCannotChangeRoutingType() throws Exception {
   final String queueName = "updateQueue";
   final SimpleString queueNameString = new SimpleString(queueName);
   final String addressName = "address";
   final SimpleString addressSimpleString = new SimpleString(addressName);
   final int oldMaxConsumers = 10;
   final RoutingType oldRoutingType = RoutingType.MULTICAST;
   final boolean oldPurgeOnNoConsumers = false;
   final Set<RoutingType> supportedRoutingTypes = EnumSet.of(oldRoutingType);
   final AddressInfo addressInfo = new AddressInfo(addressSimpleString, EnumSet.copyOf(supportedRoutingTypes));
   server.addAddressInfo(addressInfo);
   server.createQueue(new QueueConfiguration(queueNameString).setAddress(addressSimpleString).setRoutingType(oldRoutingType).setMaxConsumers(oldMaxConsumers).setPurgeOnNoConsumers(oldPurgeOnNoConsumers).setAutoCreateAddress(false));

   final RoutingType newRoutingType = RoutingType.ANYCAST;
   final UpdateQueue updateQueue = new UpdateQueue();
   updateQueue.setName(queueName);
   updateQueue.setAnycast(true);
   updateQueue.setMulticast(false);
   updateQueue.setMaxConsumers(-1);
   updateQueue.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error)));

   checkExecutionFailure(updateQueue, "AMQ229211");

   final QueueQueryResult queueQueryResult = server.queueQuery(queueNameString);
   assertEquals("maxConsumers", oldMaxConsumers, queueQueryResult.getMaxConsumers());
   assertEquals("routingType", oldRoutingType, queueQueryResult.getRoutingType());
   assertTrue("purgeOnNoConsumers", oldPurgeOnNoConsumers == queueQueryResult.isPurgeOnNoConsumers());
}
 
Example 8
Source File: QueueCommandTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdateCoreQueueCannotLowerMaxConsumers() throws Exception {
   final String queueName = "updateQueue";
   final SimpleString queueNameString = new SimpleString(queueName);
   final String addressName = "address";
   final SimpleString addressSimpleString = new SimpleString(addressName);
   final int oldMaxConsumers = 2;
   final RoutingType oldRoutingType = RoutingType.MULTICAST;
   final boolean oldPurgeOnNoConsumers = false;
   final AddressInfo addressInfo = new AddressInfo(addressSimpleString, oldRoutingType);
   server.addAddressInfo(addressInfo);
   server.createQueue(new QueueConfiguration(queueNameString).setAddress(addressSimpleString).setRoutingType(oldRoutingType).setMaxConsumers(oldMaxConsumers).setPurgeOnNoConsumers(oldPurgeOnNoConsumers).setAutoCreateAddress(false));

   server.locateQueue(queueNameString).addConsumer(new DummyServerConsumer());
   server.locateQueue(queueNameString).addConsumer(new DummyServerConsumer());

   final int newMaxConsumers = 1;
   final UpdateQueue updateQueue = new UpdateQueue();
   updateQueue.setName(queueName);
   updateQueue.setMaxConsumers(newMaxConsumers);
   updateQueue.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error)));

   checkExecutionFailure(updateQueue, "AMQ229210");

   final QueueQueryResult queueQueryResult = server.queueQuery(queueNameString);
   assertEquals("maxConsumers", oldMaxConsumers, queueQueryResult.getMaxConsumers());
}
 
Example 9
Source File: RequestReplyMultiProtocolTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Before
public void setupQueue() throws Exception {
   Wait.assertTrue(server::isStarted);
   Wait.assertTrue(server::isActive);
   this.server.createQueue(new QueueConfiguration(queueName).setRoutingType(RoutingType.ANYCAST));
   this.server.createQueue(new QueueConfiguration(replyQueue).setRoutingType(RoutingType.ANYCAST));
   AddressInfo info = new AddressInfo(topicName, RoutingType.MULTICAST);
   this.server.addAddressInfo(info);
}
 
Example 10
Source File: RequestReplyNonJMSTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Before
public void setupQueue() throws Exception {
   Wait.assertTrue(server::isStarted);
   Wait.assertTrue(server::isActive);
   this.server.createQueue(new QueueConfiguration(queueName).setRoutingType(RoutingType.ANYCAST));
   this.server.createQueue(new QueueConfiguration(replyQueue).setRoutingType(RoutingType.ANYCAST));
   AddressInfo info = new AddressInfo(topicName, RoutingType.MULTICAST);
   this.server.addAddressInfo(info);
}
 
Example 11
Source File: QueueAbstractPacket.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public static SimpleString getOldPrefixedAddress(SimpleString address, RoutingType routingType) {
   if (routingType == RoutingType.MULTICAST && !address.startsWith(OLD_TOPIC_PREFIX)) {
      return OLD_TOPIC_PREFIX.concat(address);
   } else if (routingType == RoutingType.ANYCAST && !address.startsWith(OLD_QUEUE_PREFIX)) {
      return OLD_QUEUE_PREFIX.concat(address);
   }

   return address;
}
 
Example 12
Source File: QueueQueryImpl.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public QueueQueryImpl(final boolean durable,
                      final boolean temporary,
                      final int consumerCount,
                      final long messageCount,
                      final SimpleString filterString,
                      final SimpleString address,
                      final SimpleString name,
                      final boolean exists,
                      final boolean autoCreateQueues) {
   this(durable, temporary, consumerCount, messageCount, filterString, address, name, exists, autoCreateQueues, -1, false, false, RoutingType.MULTICAST);
}
 
Example 13
Source File: SessionQueueQueryResponseMessage_V3.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public SessionQueueQueryResponseMessage_V3() {
   this(null, null, false, false, null, 0, 0, false, false, false, false, RoutingType.MULTICAST, -1, null, null,null, null, null, null, null, null, null, null, null, null, null, null, null);
}
 
Example 14
Source File: ServerSessionPacketHandler.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
private RoutingType getRoutingTypeFromAddress(SimpleString address) {
   if (address.startsWith(PacketImpl.OLD_QUEUE_PREFIX) || address.startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX)) {
      return RoutingType.ANYCAST;
   }
   return RoutingType.MULTICAST;
}
 
Example 15
Source File: ActiveMQServerImpl.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Override
public QueueQueryResult queueQuery(SimpleString name) {
   if (name == null) {
      throw ActiveMQMessageBundle.BUNDLE.queueNameIsNull();
   }

   SimpleString realName = CompositeAddress.extractQueueName(name);

   final QueueQueryResult response;

   Binding binding = getPostOffice().getBinding(realName);

   final SimpleString addressName = binding != null && binding.getType() == BindingType.LOCAL_QUEUE
         ? binding.getAddress() : CompositeAddress.extractAddressName(name);

   final AddressSettings addressSettings = getAddressSettingsRepository().getMatch(addressName.toString());

   boolean autoCreateQueues = addressSettings.isAutoCreateQueues();
   boolean defaultPurgeOnNoConsumers = addressSettings.isDefaultPurgeOnNoConsumers();
   int defaultMaxConsumers = addressSettings.getDefaultMaxConsumers();
   boolean defaultExclusiveQueue = addressSettings.isDefaultExclusiveQueue();
   boolean defaultLastValueQueue = addressSettings.isDefaultLastValueQueue();
   SimpleString defaultLastValueKey = addressSettings.getDefaultLastValueKey();
   boolean defaultNonDestructive = addressSettings.isDefaultNonDestructive();
   int defaultConsumersBeforeDispatch = addressSettings.getDefaultConsumersBeforeDispatch();
   long defaultDelayBeforeDispatch = addressSettings.getDefaultDelayBeforeDispatch();
   int defaultConsumerWindowSize = addressSettings.getDefaultConsumerWindowSize();
   boolean defaultGroupRebalance = addressSettings.isDefaultGroupRebalance();
   int defaultGroupBuckets = addressSettings.getDefaultGroupBuckets();
   SimpleString defaultGroupFirstKey = addressSettings.getDefaultGroupFirstKey();
   long autoDeleteQueuesDelay = addressSettings.getAutoDeleteQueuesDelay();
   long autoDeleteQueuesMessageCount = addressSettings.getAutoDeleteQueuesMessageCount();
   long defaultRingSize = addressSettings.getDefaultRingSize();
   boolean defaultEnabled = ActiveMQDefaultConfiguration.getDefaultEnabled();

   SimpleString managementAddress = getManagementService() != null ? getManagementService().getManagementAddress() : null;

   if (binding != null && binding.getType() == BindingType.LOCAL_QUEUE) {
      Queue queue = (Queue) binding.getBindable();

      Filter filter = queue.getFilter();

      SimpleString filterString = filter == null ? null : filter.getFilterString();

      response = new QueueQueryResult(realName, binding.getAddress(), queue.isDurable(), queue.isTemporary(), filterString, queue.getConsumerCount(), queue.getMessageCount(), autoCreateQueues, true, queue.isAutoCreated(), queue.isPurgeOnNoConsumers(), queue.getRoutingType(), queue.getMaxConsumers(), queue.isExclusive(), queue.isGroupRebalance(), queue.getGroupBuckets(), queue.getGroupFirstKey(), queue.isLastValue(), queue.getLastValueKey(), queue.isNonDestructive(), queue.getConsumersBeforeDispatch(), queue.getDelayBeforeDispatch(), queue.isAutoDelete(), queue.getAutoDeleteDelay(), queue.getAutoDeleteMessageCount(), defaultConsumerWindowSize, queue.getRingSize(), queue.isEnabled());
   } else if (realName.equals(managementAddress)) {
      // make an exception for the management address (see HORNETQ-29)
      response = new QueueQueryResult(realName, managementAddress, true, false, null, -1, -1, autoCreateQueues, true, false, false, RoutingType.MULTICAST, -1, false, false, null, null, null,null, null, null, null, null, null, null, defaultConsumerWindowSize, null, null);
   } else {
      response = new QueueQueryResult(realName, addressName, true, false, null, 0, 0, autoCreateQueues, false, false, defaultPurgeOnNoConsumers, RoutingType.MULTICAST, defaultMaxConsumers, defaultExclusiveQueue, defaultGroupRebalance, defaultGroupBuckets, defaultGroupFirstKey, defaultLastValueQueue, defaultLastValueKey, defaultNonDestructive, defaultConsumersBeforeDispatch, defaultDelayBeforeDispatch, isAutoDelete(false, addressSettings), autoDeleteQueuesDelay, autoDeleteQueuesMessageCount, defaultConsumerWindowSize, defaultRingSize, defaultEnabled);
   }

   return response;
}