Java Code Examples for org.apache.activemq.command.ActiveMQDestination#createDestination()

The following examples show how to use org.apache.activemq.command.ActiveMQDestination#createDestination() . 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: OneopsAuthBrokerTest.java    From oneops with Apache License 2.0 6 votes vote down vote up
@Test(priority=5)
public void addConsumerTest(){
	//set up a mock for ConsumerInfo
	ActiveMQDestination activeMQDestinationMQ =  ActiveMQDestination.createDestination("mockMQDestionation",  (byte) 1 );		
	activeMQDestinationMQ.setPhysicalName(MQ_PHYSICAL_NAME);
	
	ConsumerInfo consumerInfoActiveMQ = mock(ConsumerInfo.class);
	when(consumerInfoActiveMQ.getDestination()).thenReturn(activeMQDestinationMQ);
	
	//set up mock for ProducerInfo
	producerInfo = mock(ProducerInfo.class);
	when(producerInfo.getDestination()).thenReturn(activeMQDestination);	
	
	try {
		this.oneopsAuthBroker.addConsumer(connectionContextMock, consumerInfoActiveMQ);
	} catch (Exception e) {
		logger.warn("caught exception, make sure Broker is mocked",e);
		throw new RuntimeException(e);
	}
	
}
 
Example 2
Source File: DestinationRemoveRestartTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public void doAddDestination() throws Exception {
   boolean res = false;

   ActiveMQDestination amqDestination = ActiveMQDestination.createDestination(destinationName, destinationType);
   broker.getRegionBroker().addDestination(broker.getAdminConnectionContext(), amqDestination, true);

   final ActiveMQDestination[] list = broker.getRegionBroker().getDestinations();
   for (final ActiveMQDestination element : list) {
      final Destination destination = broker.getDestination(element);
      if (destination.getActiveMQDestination().getPhysicalName().equals(destinationName)) {
         res = true;
         break;
      }
   }

   assertTrue("Adding destination Failed", res);
}
 
Example 3
Source File: AmqpSupport.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * Given an AMQP endpoint, deduce the appropriate ActiveMQDestination type and create
 * a new instance.  By default if the endpoint address does not carry the standard prefix
 * value then we default to a Queue type destination.  If the endpoint is null or is an
 * AMQP Coordinator type endpoint this method returns null to indicate no destination
 * can be mapped.
 *
 * @param endpoint the AMQP endpoint to construct an ActiveMQDestination from.
 * @return a new ActiveMQDestination that best matches the address of the given endpoint
 * @throws AmqpProtocolException if an error occurs while deducing the destination type.
 */
public static ActiveMQDestination createDestination(Object endpoint) throws AmqpProtocolException {
   if (endpoint == null) {
      return null;
   } else if (endpoint instanceof Coordinator) {
      return null;
   } else if (endpoint instanceof org.apache.qpid.proton.amqp.messaging.Terminus) {
      org.apache.qpid.proton.amqp.messaging.Terminus terminus = (org.apache.qpid.proton.amqp.messaging.Terminus) endpoint;
      if (terminus.getAddress() == null || terminus.getAddress().length() == 0) {
         if (terminus instanceof org.apache.qpid.proton.amqp.messaging.Source) {
            throw new AmqpProtocolException("amqp:invalid-field", "source address not set");
         } else {
            throw new AmqpProtocolException("amqp:invalid-field", "target address not set");
         }
      }

      return ActiveMQDestination.createDestination(terminus.getAddress(), ActiveMQDestination.QUEUE_TYPE);
   } else {
      throw new RuntimeException("Unexpected terminus type: " + endpoint);
   }
}
 
Example 4
Source File: MessageRedistributionTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private void closeConsumerAndConnectionConcurrently(int targetNode, int remoteNode) throws Exception {

      String targetUri = getServerUri(targetNode);
      ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(targetUri);
      Connection conn = null;
      CountDownLatch active = new CountDownLatch(1);
      try {
         conn = factory.createConnection();
         conn.start();
         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
         Destination dest = ActiveMQDestination.createDestination("queue0", ActiveMQDestination.QUEUE_TYPE);
         ConsumerThread consumer = new ConsumerThread(session, dest);
         consumer.setMessageCount(0);
         consumer.setFinished(active);
         consumer.start();

         assertTrue("consumer takes too long to finish!", active.await(5, TimeUnit.SECONDS));
      } finally {
         conn.close();
      }

      Wait.waitFor(() -> getRemoteQueueBinding(servers[remoteNode]) != null);

      //check remote server's consumer count
      RemoteQueueBinding remoteBinding = getRemoteQueueBinding(servers[remoteNode]);

      assertNotNull(remoteBinding);

      Wait.waitFor(() -> remoteBinding.consumerCount() >= 0);
      int count = remoteBinding.consumerCount();
      assertTrue("consumer count should never be negative " + count, count >= 0);
   }
 
Example 5
Source File: DemandForwardingBridgeFilterTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private void assertReceiveNoMessageOn(String destinationName,
                                      byte destinationType) throws Exception, InterruptedException {

   ActiveMQDestination destination = ActiveMQDestination.createDestination(destinationName, destinationType);

   // Send the message to the local broker.
   producerConnection.send(createMessage(producerInfo, destination, destinationType));

   // Make sure the message was delivered via the remote.
   Message m = createConsumerAndReceiveMessage(destination);
   assertNull(m);
}
 
Example 6
Source File: BrokerNetworkWithStuckMessagesTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected ActiveMQDestination createDestinationInfo(StubConnection connection,
                                                    ConnectionInfo connectionInfo1,
                                                    byte destinationType) throws Exception {
   if ((destinationType & ActiveMQDestination.TEMP_MASK) != 0) {
      DestinationInfo info = createTempDestinationInfo(connectionInfo1, destinationType);
      connection.send(info);
      return info.getDestination();
   } else {
      return ActiveMQDestination.createDestination(queueName, destinationType);
   }
}
 
Example 7
Source File: BrokerTestSupport.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected ActiveMQDestination createDestinationInfo(StubConnection connection,
                                                    ConnectionInfo connectionInfo1,
                                                    byte destinationType) throws Exception {
   if ((destinationType & ActiveMQDestination.TEMP_MASK) != 0) {
      DestinationInfo info = createTempDestinationInfo(connectionInfo1, destinationType);
      connection.send(info);
      return info.getDestination();
   } else {
      return ActiveMQDestination.createDestination(queueName, destinationType);
   }
}
 
Example 8
Source File: BrokerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void testWildcardConsume() throws Exception {

      // Setup a first connection
      StubConnection connection1 = createConnection();
      ConnectionInfo connectionInfo1 = createConnectionInfo();
      SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
      ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
      connection1.send(connectionInfo1);
      connection1.send(sessionInfo1);
      connection1.send(producerInfo1);

      // setup the wildcard consumer.
      ActiveMQDestination compositeDestination = ActiveMQDestination.createDestination("WILD.*.TEST", destinationType);
      ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, compositeDestination);
      consumerInfo1.setPrefetchSize(100);
      connection1.send(consumerInfo1);

      // These two message should NOT match the wild card.
      connection1.send(createMessage(producerInfo1, ActiveMQDestination.createDestination("WILD.CARD", destinationType), deliveryMode));
      connection1.send(createMessage(producerInfo1, ActiveMQDestination.createDestination("WILD.TEST", destinationType), deliveryMode));

      // These two message should match the wild card.
      ActiveMQDestination d1 = ActiveMQDestination.createDestination("WILD.CARD.TEST", destinationType);
      connection1.send(createMessage(producerInfo1, d1, deliveryMode));

      Message m = receiveMessage(connection1);
      assertNotNull(m);
      assertEquals(d1, m.getDestination());

      ActiveMQDestination d2 = ActiveMQDestination.createDestination("WILD.FOO.TEST", destinationType);
      connection1.request(createMessage(producerInfo1, d2, deliveryMode));
      m = receiveMessage(connection1);
      assertNotNull(m);
      assertEquals(d2, m.getDestination());

      assertNoMessagesLeft(connection1);
      connection1.send(closeConnectionInfo(connectionInfo1));
   }
 
Example 9
Source File: BrokerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void testCompositeConsume() throws Exception {

      // Setup a first connection
      StubConnection connection1 = createConnection();
      ConnectionInfo connectionInfo1 = createConnectionInfo();
      SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
      ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
      connection1.send(connectionInfo1);
      connection1.send(sessionInfo1);
      connection1.send(producerInfo1);

      // setup the composite consumer.
      ActiveMQDestination compositeDestination = ActiveMQDestination.createDestination("A,B", destinationType);
      ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, compositeDestination);
      consumerInfo1.setRetroactive(true);
      consumerInfo1.setPrefetchSize(100);
      connection1.send(consumerInfo1);

      // Publish to the two destinations
      ActiveMQDestination destinationA = ActiveMQDestination.createDestination("A", destinationType);
      ActiveMQDestination destinationB = ActiveMQDestination.createDestination("B", destinationType);

      // Send a message to each destination .
      connection1.send(createMessage(producerInfo1, destinationA, deliveryMode));
      connection1.send(createMessage(producerInfo1, destinationB, deliveryMode));

      // The consumer should get both messages.
      for (int i = 0; i < 2; i++) {
         Message m1 = receiveMessage(connection1);
         assertNotNull(m1);
      }

      assertNoMessagesLeft(connection1);
      connection1.send(closeConnectionInfo(connectionInfo1));
   }
 
Example 10
Source File: RequestReplyToTopicViaThreeNetworkHopsTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected void makeConnectionTo(EmbeddedTcpBroker other, boolean duplex_f, boolean queue_f) throws Exception {
   NetworkConnector nw_conn;
   String prefix;
   ActiveMQDestination excl_dest;
   ArrayList<ActiveMQDestination> excludes;

   nw_conn = new DiscoveryNetworkConnector(new URI("static:(" + other.tcpUrl + ")"));
   nw_conn.setDuplex(duplex_f);

   if (queue_f)
      nw_conn.setConduitSubscriptions(false);
   else
      nw_conn.setConduitSubscriptions(true);

   nw_conn.setNetworkTTL(3);
   nw_conn.setSuppressDuplicateQueueSubscriptions(true);
   nw_conn.setDecreaseNetworkConsumerPriority(true);
   nw_conn.setBridgeTempDestinations(queue_f);

   if (queue_f) {
      prefix = "queue";
      excl_dest = ActiveMQDestination.createDestination(">", ActiveMQDestination.TOPIC_TYPE);
   } else {
      prefix = "topic";
      excl_dest = ActiveMQDestination.createDestination(">", ActiveMQDestination.QUEUE_TYPE);
   }

   excludes = new ArrayList<>();
   excludes.add(excl_dest);
   nw_conn.setExcludedDestinations(excludes);

   if (duplex_f)
      nw_conn.setName(this.brokerId + "<-" + prefix + "->" + other.brokerId);
   else
      nw_conn.setName(this.brokerId + "-" + prefix + "->" + other.brokerId);

   brokerSvc.addNetworkConnector(nw_conn);
}
 
Example 11
Source File: OneopsAuthBrokerTest.java    From oneops with Apache License 2.0 4 votes vote down vote up
@BeforeClass
/**
 * sets up mocks which get re-used in the tests
 */
public void setUp()  {		

	//set up the mock for CMSClient
	cmsClient = mock(CMSClient.class);
	//- and the mock data that mock will return
	CmsCISimple cmsCISimple = new CmsCISimple();
	Map<String,String> ciAttributes = new HashMap<String,String>(1);
	ciAttributes.put(AUTH_ATTR_KEY, AUTH_KEY_VALUE);
	cmsCISimple.setCiAttributes(ciAttributes);
	//for getCloud(user-name,cloud-name)
	when(cmsClient.getCloudCi(CLOUD_NAME, CLOUD_NAME)).thenReturn(cmsCISimple);
	when(cmsClient.getCloudCi("user", CLOUD_NAME)).thenReturn(cmsCISimple);
	
	//set up the mock for ConnectionInfo:  system/blahblah
	connectionInfoSystem = mock(ConnectionInfo.class);
	when(connectionInfoSystem.getClientId()).thenReturn(SYSTEM_CLIENT_ID);
	when(connectionInfoSystem.getUserName()).thenReturn(SYSTEM_CLIENT_ID + ":" + CLOUD_NAME);
	when(connectionInfoSystem.getPassword()).thenReturn(AUTH_KEY_VALUE);
	
	//and another ConnectionInfo stubbedClientId/foobarbizbat
	connectionBadInfo = mock(ConnectionInfo.class);
	when(connectionBadInfo.getClientId()).thenReturn(MOCK_CLIENT_ID);
	when(connectionBadInfo.getUserName()).thenReturn(CLOUD_NAME + ":" + CLOUD_NAME);
	when(connectionBadInfo.getPassword()).thenReturn(CONN_INFO_PASS_BAD); //to cause fail paasword check		
	
	//and another ConnectionInfo stubbedClientId/blahblah
	connectionInfoUser = mock(ConnectionInfo.class);
	when(connectionInfoUser.getClientId()).thenReturn(MOCK_CLIENT_ID);
	when(connectionInfoUser.getUserName()).thenReturn("user" + ":" + CLOUD_NAME);
	when(connectionInfoUser.getPassword()).thenReturn("blahblah"); //to cause fail paasword check		
	
	// construct ConnectionContext, passing it the system's connection info
	connectionContextSystem = new ConnectionContext(connectionInfoSystem);
	
	//create a mock ConnectionContext
	connectionContextMock = mock(ConnectionContext.class);
	 final Connection connectionMock = mock(Connection.class);
	when(connectionMock.getRemoteAddress()).thenReturn(MOCK_REMOTE_ADDR);
			
	when(connectionContextMock.getClientId()).thenReturn(MOCK_CLIENT_ID);
	when(connectionContextMock.getConnection()).thenAnswer(new Answer<Connection>() {
		@Override
		public Connection answer(InvocationOnMock invocation)
				throws Throwable {
			return connectionMock;
		}
	});
	
	//set up mock for ConsumerInfo
	activeMQDestination =  ActiveMQDestination.createDestination("mockMQDestionation",  (byte) 1 );		
	activeMQDestination.setPhysicalName(MOCK_PHYSICAL_NAME);
	
	consumerInfo = mock(ConsumerInfo.class);
	when(consumerInfo.getDestination()).thenReturn(activeMQDestination);
}
 
Example 12
Source File: BrokerTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public void testCompositeSend() throws Exception {

      // Setup a first connection
      StubConnection connection1 = createConnection();
      ConnectionInfo connectionInfo1 = createConnectionInfo();
      SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
      ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
      connection1.send(connectionInfo1);
      connection1.send(sessionInfo1);
      connection1.send(producerInfo1);

      ActiveMQDestination destinationA = ActiveMQDestination.createDestination("A", destinationType);
      ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destinationA);
      consumerInfo1.setRetroactive(true);
      consumerInfo1.setPrefetchSize(100);
      connection1.request(consumerInfo1);

      // Setup a second connection
      StubConnection connection2 = createConnection();
      ConnectionInfo connectionInfo2 = createConnectionInfo();
      SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
      connection2.send(connectionInfo2);
      connection2.send(sessionInfo2);

      ActiveMQDestination destinationB = ActiveMQDestination.createDestination("B", destinationType);
      ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destinationB);
      consumerInfo2.setRetroactive(true);
      consumerInfo2.setPrefetchSize(100);
      connection2.request(consumerInfo2);

      // Send the messages to the composite destination.
      ActiveMQDestination compositeDestination = ActiveMQDestination.createDestination("A,B", destinationType);
      for (int i = 0; i < 4; i++) {
         connection1.request(createMessage(producerInfo1, compositeDestination, deliveryMode));
      }

      // The messages should have been delivered to both the A and B
      // destination.
      for (int i = 0; i < 4; i++) {
         Message m1 = receiveMessage(connection1);
         Message m2 = receiveMessage(connection2);

         assertNotNull(m1);
         assertNotNull(m2);

         assertEquals(m1.getMessageId(), m2.getMessageId());
         assertEquals(compositeDestination, m1.getOriginalDestination());
         assertEquals(compositeDestination, m2.getOriginalDestination());

         connection1.request(createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE));
         connection2.request(createAck(consumerInfo2, m2, 1, MessageAck.STANDARD_ACK_TYPE));

      }

      assertNoMessagesLeft(connection1);
      assertNoMessagesLeft(connection2);

      connection1.send(closeConnectionInfo(connectionInfo1));
      connection2.send(closeConnectionInfo(connectionInfo2));
   }
 
Example 13
Source File: DemandForwardingBridgeFilterTest.java    From activemq-artemis with Apache License 2.0 3 votes vote down vote up
private void assertReceiveMessageOn(String destinationName,
                                    byte destinationType) throws Exception, InterruptedException {

   ActiveMQDestination destination = ActiveMQDestination.createDestination(destinationName, destinationType);

   // Send the message to the local broker.
   producerConnection.send(createMessage(producerInfo, destination, destinationType));

   // Make sure the message was delivered via the remote.
   Message m = createConsumerAndReceiveMessage(destination);

   assertNotNull(m);
}