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

The following examples show how to use org.apache.activemq.artemis.api.core.RoutingType#ANYCAST . 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: 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 4
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 5
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 6
Source File: AMQSession.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private boolean checkAutoCreateQueue(SimpleString queueName, boolean isTemporary) throws Exception {
   boolean hasQueue = true;
   if (!connection.containsKnownDestination(queueName)) {

      BindingQueryResult bindingQuery = server.bindingQuery(queueName);
      QueueQueryResult queueBinding = server.queueQuery(queueName);

      try {
         if (!queueBinding.isExists()) {
            if (bindingQuery.isAutoCreateQueues()) {
               SimpleString queueNameToUse = queueName;
               SimpleString addressToUse = queueName;
               RoutingType routingTypeToUse = RoutingType.ANYCAST;
               if (CompositeAddress.isFullyQualified(queueName.toString())) {
                  addressToUse = CompositeAddress.extractAddressName(queueName);
                  queueNameToUse = CompositeAddress.extractQueueName(queueName);
                  if (bindingQuery.getAddressInfo() != null) {
                     routingTypeToUse = bindingQuery.getAddressInfo().getRoutingType();
                  } else {
                     AddressSettings as = server.getAddressSettingsRepository().getMatch(addressToUse.toString());
                     routingTypeToUse = as.getDefaultAddressRoutingType();
                  }
               }
               coreSession.createQueue(new QueueConfiguration(queueNameToUse).setAddress(addressToUse).setRoutingType(routingTypeToUse).setTemporary(isTemporary).setAutoCreated(true));
               connection.addKnownDestination(queueName);
            } else {
               hasQueue = false;
            }
         }
      } catch (ActiveMQQueueExistsException e) {
         // In case another thread created the queue before us but after we did the binding query
         hasQueue = true;
      }

   }
   return hasQueue;
}
 
Example 7
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetRoutingType() {
   RoutingType type = RoutingType.ANYCAST;

   MessageImpl protonMessage = (MessageImpl) Message.Factory.create();
   AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage);

   assertNull(decoded.getRoutingType());
   decoded.setRoutingType(type);
   assertEquals(type, decoded.getRoutingType());
}
 
Example 8
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetRoutingTypeToClear() {
   RoutingType type = RoutingType.ANYCAST;

   MessageImpl protonMessage = (MessageImpl) Message.Factory.create();
   AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage);

   assertNull(decoded.getRoutingType());
   decoded.setRoutingType(type);
   assertEquals(type, decoded.getRoutingType());
   decoded.setRoutingType(null);
   assertNull(decoded.getRoutingType());
}
 
Example 9
Source File: LocalQueueBinding.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public SimpleString getRoutingName() {
   if (queue.getRoutingType() == RoutingType.ANYCAST) {
      return address;
   }
   return name;
}
 
Example 10
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 11
Source File: UpdateQueueTest.java    From activemq-artemis with Apache License 2.0 3 votes vote down vote up
@Test
public void testUpdateAddress() throws Exception {
   ActiveMQServer server = createServer(true, true);

   ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();

   server.start();

   SimpleString ADDRESS = SimpleString.toSimpleString("queue.0");

   AddressInfo infoAdded = new AddressInfo(ADDRESS, RoutingType.ANYCAST);

   server.addAddressInfo(infoAdded);

   server.updateAddressInfo(ADDRESS, infoAdded.getRoutingTypes());

   server.stop();
   server.start();

   AddressInfo infoAfterRestart = server.getPostOffice().getAddressInfo(ADDRESS);

   Assert.assertEquals(infoAdded.getId(), infoAfterRestart.getId());

   EnumSet<RoutingType> completeSet = EnumSet.allOf(RoutingType.class);

   server.updateAddressInfo(ADDRESS, completeSet);

   server.stop();
   server.start();

   infoAfterRestart = server.getPostOffice().getAddressInfo(ADDRESS);

   // it was changed.. so new ID
   Assert.assertNotEquals(infoAdded.getId(), infoAfterRestart.getId());
}