org.apache.activemq.command.ActiveMQDestination Java Examples

The following examples show how to use org.apache.activemq.command.ActiveMQDestination. 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: JmsCreateConsumerInOnMessageTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests if a consumer can be created asynchronusly
 *
 * @throws Exception
 */
@Test
public void testCreateConsumer() throws Exception {
   connection.setClientID("connection:" + "JmsCreateConsumerInOnMessageTest");
   publisherSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   consumerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   topic = (Topic) super.createDestination(consumerSession, ActiveMQDestination.TOPIC_TYPE);
   consumer = consumerSession.createConsumer(topic);
   consumer.setMessageListener(this);
   producer = publisherSession.createProducer(topic);
   connection.start();
   Message msg = publisherSession.createMessage();
   producer.send(msg);

   synchronized (lock) {
      long timeout = System.currentTimeMillis() + 3000;
      while (testConsumer == null && timeout > System.currentTimeMillis()) {
         lock.wait(1000);
      }
   }
   assertTrue(testConsumer != null);
}
 
Example #2
Source File: AdvisoryTempDestinationTests.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public void testMessageExpiredAdvisory() throws Exception {
   Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Queue queue = s.createQueue(getClass().getName());
   MessageConsumer consumer = s.createConsumer(queue);
   assertNotNull(consumer);

   Topic advisoryTopic = AdvisorySupport.getExpiredMessageTopic((ActiveMQDestination) queue);
   MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
   //start throwing messages at the consumer
   MessageProducer producer = s.createProducer(queue);
   producer.setTimeToLive(1);
   for (int i = 0; i < MESSAGE_COUNT; i++) {
      BytesMessage m = s.createBytesMessage();
      m.writeBytes(new byte[1024]);
      producer.send(m);
   }

   Message msg = advisoryConsumer.receive(5000);
   assertNotNull(msg);
}
 
Example #3
Source File: VirtualTopicNetworkClusterReactivationTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
   maxSetupTime = 1000;
   super.setAutoFail(true);
   super.setUp();
   final String options = "?persistent=true&useJmx=false&deleteAllMessagesOnStartup=true";

   BrokerService brokerServiceA = createBroker(new URI(String.format("broker:(%s)/%s%s", BROKER_A_TRANSPORT_URL, BROKER_A, options)));
   brokerServiceA.setDestinationPolicy(buildPolicyMap());
   brokerServiceA.setDestinations(new ActiveMQDestination[]{queue});

   BrokerService brokerServiceB = createBroker(new URI(String.format("broker:(%s)/%s%s", BROKER_B_TRANSPORT_URL, BROKER_B, options)));
   brokerServiceB.setDestinationPolicy(buildPolicyMap());
   brokerServiceB.setDestinations(new ActiveMQDestination[]{queue});

   // bridge brokers to each other statically (static: discovery)
   bridgeBrokers(BROKER_A, BROKER_B);
   bridgeBrokers(BROKER_B, BROKER_A);

   startAllBrokers();
}
 
Example #4
Source File: GeneralInteropTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private void sendBytesMessageUsingOpenWire(byte[] bytesData) throws Exception {
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);

   final ActiveMQMessageProducer producer = (ActiveMQMessageProducer) session.createProducer(destination);

   BytesMessage bytesMessage = session.createBytesMessage();
   bytesMessage.writeBytes(bytesData);
   bytesMessage.writeBoolean(true);
   bytesMessage.writeLong(99999L);
   bytesMessage.writeChar('h');
   bytesMessage.writeInt(987);
   bytesMessage.writeShort((short) 1099);
   bytesMessage.writeUTF("hellobytes");

   producer.send(bytesMessage);
}
 
Example #5
Source File: AdvisoryTempDestinationTests.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public void testMessageDeliveryAdvisory() throws Exception {
   Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   TemporaryQueue queue = s.createTemporaryQueue();
   MessageConsumer consumer = s.createConsumer(queue);
   assertNotNull(consumer);

   Topic advisoryTopic = AdvisorySupport.getMessageDeliveredAdvisoryTopic((ActiveMQDestination) queue);
   MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
   //start throwing messages at the consumer
   MessageProducer producer = s.createProducer(queue);

   BytesMessage m = s.createBytesMessage();
   m.writeBytes(new byte[1024]);
   producer.send(m);

   Message msg = advisoryConsumer.receive(1000);
   assertNotNull(msg);
}
 
Example #6
Source File: JmsTopicSelectorTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
@Before
public void setUp() throws Exception {
   super.setUp();

   if (durable) {
      connection.setClientID(getClass().getName());
   }

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

   if (topic) {
      consumerDestination = this.createDestination(session, ActiveMQDestination.TOPIC_TYPE);
      producerDestination = this.createDestination(session, ActiveMQDestination.TOPIC_TYPE);
   } else {
      consumerDestination = this.createDestination(session, ActiveMQDestination.QUEUE_TYPE);
      producerDestination = this.createDestination(session, ActiveMQDestination.QUEUE_TYPE);
   }

   producer = session.createProducer(producerDestination);
   producer.setDeliveryMode(deliveryMode);

   connection.start();
}
 
Example #7
Source File: CompressionOverNetworkTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private void waitForConsumerRegistration(final BrokerService brokerService,
                                         final int min,
                                         final ActiveMQDestination destination) throws Exception {
   assertTrue("Internal bridge consumers registered in time", Wait.waitFor(new Wait.Condition() {
      @Override
      public boolean isSatisified() throws Exception {
         Object[] bridges = brokerService.getNetworkConnectors().get(0).bridges.values().toArray();
         if (bridges.length > 0) {
            LOG.info(brokerService + " bridges " + Arrays.toString(bridges));
            DemandForwardingBridgeSupport demandForwardingBridgeSupport = (DemandForwardingBridgeSupport) bridges[0];
            ConcurrentMap<ConsumerId, DemandSubscription> forwardingBridges = demandForwardingBridgeSupport.getLocalSubscriptionMap();

            LOG.info(brokerService + " bridge " + demandForwardingBridgeSupport + ", localSubs: " + forwardingBridges);
            if (!forwardingBridges.isEmpty()) {
               for (DemandSubscription demandSubscription : forwardingBridges.values()) {
                  if (demandSubscription.getLocalInfo().getDestination().equals(destination)) {
                     LOG.info(brokerService + " DemandSubscription " + demandSubscription + ", size: " + demandSubscription.size());
                     return demandSubscription.size() >= min;
                  }
               }
            }
         }
         return false;
      }
   }));
}
 
Example #8
Source File: ConnectorXBeanConfigTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public void testConnectorConfiguredCorrectly() throws Exception {

      TransportConnector connector = brokerService.getTransportConnectors().get(0);

      assertEquals(new URI("tcp://localhost:61636"), connector.getUri());
      assertTrue(connector.getTaskRunnerFactory() == brokerService.getTaskRunnerFactory());

      NetworkConnector netConnector = brokerService.getNetworkConnectors().get(0);
      List<ActiveMQDestination> excludedDestinations = netConnector.getExcludedDestinations();
      assertEquals(new ActiveMQQueue("exclude.test.foo"), excludedDestinations.get(0));
      assertEquals(new ActiveMQTopic("exclude.test.bar"), excludedDestinations.get(1));

      List<ActiveMQDestination> dynamicallyIncludedDestinations = netConnector.getDynamicallyIncludedDestinations();
      assertEquals(new ActiveMQQueue("include.test.foo"), dynamicallyIncludedDestinations.get(0));
      assertEquals(new ActiveMQTopic("include.test.bar"), dynamicallyIncludedDestinations.get(1));
   }
 
Example #9
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 #10
Source File: OneopsAuthBroker.java    From oneops with Apache License 2.0 6 votes vote down vote up
/**
 * Add message producer.
 *
 * @param context
 * @param info
 * @throws Exception
 * @see org.apache.activemq.broker.BrokerFilter#addProducer(org.apache.activemq.broker.ConnectionContext, org.apache.activemq.command.ProducerInfo)
 */
public void addProducer(ConnectionContext context, ProducerInfo info) throws Exception {

    Connection conn = context.getConnection();
    ActiveMQDestination dest = info.getDestination();
    if (dest != null) {
        String destName = dest.getPhysicalName();
        String clientId = context.getClientId();

        logger.info(">>> Got Producer Add request { Destination: " + destName
                + ", Remote Address: " + conn.getRemoteAddress()
                + ", ClientID: " + clientId
                + " }");

        String allowedDest = userMap.get(context.getClientId());
        if (allowedDest != null && (allowedDest.equals("*") || "controller.response".equals(destName))) {
            logger.info("<<< Producer allowed");
        } else {
            logger.error("<<< Destination not allowed. Producer denied!");
            throw new CmsAuthException("<<< Producer denied!");
        }
    } else {
        logger.error("<<< Got Producer Add request from Remote Address:" + conn.getRemoteAddress() + ". But destination is NULL.");
    }
    super.addProducer(context, info);
}
 
Example #11
Source File: QueueSubscriptionTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public void doMultipleClientsTest() throws Exception {
   // Create destination
   final ActiveMQDestination dest = createDestination();

   // Create consumers
   ActiveMQConnectionFactory consumerFactory = (ActiveMQConnectionFactory) createConnectionFactory();
   consumerFactory.getPrefetchPolicy().setAll(prefetchCount);

   startConsumers(consumerFactory, dest);

   startProducers(dest, messageCount);

   // Wait for messages to be received. Make it proportional to the
   // messages delivered.
   int totalMessageCount = messageCount * producerCount;
   if (dest.isTopic()) {
      totalMessageCount *= consumerCount;
   }
   waitForAllMessagesToBeReceived(totalMessageCount);
}
 
Example #12
Source File: JMSPollingConsumerQueueTest.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * Test Run Inbound Task to poll messages from Queue
 *
 * @throws Exception
 */
@Test
public void testPollingOnQueue() throws Exception {
    String queueName = "testQueue1";
    boolean isQueueExist = false;
    Properties jmsProperties = JMSTestsUtils.getJMSPropertiesForDestination(queueName, PROVIDER_URL, true);
    JMSBrokerController brokerController = new JMSBrokerController(PROVIDER_URL, jmsProperties);
    JMSPollingConsumer jmsPollingConsumer = new JMSPollingConsumer(jmsProperties, INTERVAL, INBOUND_EP_NAME);
    InboundTask task = new JMSTask(jmsPollingConsumer, INTERVAL);
    Assert.assertEquals(task.getInboundProperties().getProperty(JMSConstants.PROVIDER_URL), PROVIDER_URL);
    try {
        brokerController.startProcess();
        task.execute();
        ActiveMQDestination[] activeMQDestination = brokerController.getBrokerService().getRegionBroker().
                getDestinations();
        for (ActiveMQDestination destination : activeMQDestination) {
            if (destination.isQueue() && queueName.equals(destination.getPhysicalName())) {
                isQueueExist = true;
            }
        }
        Assert.assertTrue("Queue is not added as a subscription", isQueueExist);
    } finally {
        task.destroy();
        brokerController.stopProcess();
    }
}
 
Example #13
Source File: JMSConsumer5Test.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendReceiveBytesMessage() throws Exception {
   // Receive a message with the JMS API
   connection.start();
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   ActiveMQDestination destination = createDestination(session, destinationType);
   MessageConsumer consumer = session.createConsumer(destination);
   MessageProducer producer = session.createProducer(destination);

   BytesMessage message = session.createBytesMessage();
   message.writeBoolean(true);
   message.writeBoolean(false);
   producer.send(message);

   // Make sure only 1 message was delivered.
   BytesMessage m = (BytesMessage) consumer.receive(1000);
   assertNotNull(m);
   assertTrue(m.readBoolean());
   assertFalse(m.readBoolean());

   assertNull(consumer.receiveNoWait());
}
 
Example #14
Source File: RemoveDestinationTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveDestinationWithoutSubscriber() throws Exception {

   ActiveMQConnection amqConnection = (ActiveMQConnection) createConnection(true);
   DestinationSource destinationSource = amqConnection.getDestinationSource();
   Session session = amqConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Topic topic = session.createTopic("TEST.FOO");
   MessageProducer producer = session.createProducer(topic);
   MessageConsumer consumer = session.createConsumer(topic);

   TextMessage msg = session.createTextMessage("Hellow World");
   producer.send(msg);
   assertNotNull(consumer.receive(5000));
   Thread.sleep(1000);

   ActiveMQTopic amqTopic = (ActiveMQTopic) topic;
   assertTrue(destinationSource.getTopics().contains(amqTopic));

   consumer.close();
   producer.close();
   session.close();

   Thread.sleep(3000);
   amqConnection.destroyDestination((ActiveMQDestination) topic);
   Thread.sleep(3000);
   assertFalse(destinationSource.getTopics().contains(amqTopic));
}
 
Example #15
Source File: JMSIndividualAckTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests if acknowledged messages are being consumed.
 *
 * @throws JMSException
 */
@Test
public void testLastMessageAcked() throws JMSException {
   connection.start();
   Session session = connection.createSession(false, ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE);
   Queue queue = (Queue) this.createDestination(session, ActiveMQDestination.QUEUE_TYPE);
   MessageProducer producer = session.createProducer(queue);
   TextMessage msg1 = session.createTextMessage("msg1");
   TextMessage msg2 = session.createTextMessage("msg2");
   TextMessage msg3 = session.createTextMessage("msg3");
   producer.send(msg1);
   producer.send(msg2);
   producer.send(msg3);

   // Consume the message...
   MessageConsumer consumer = session.createConsumer(queue);
   Message msg = consumer.receive(1000);
   assertNotNull(msg);
   msg = consumer.receive(1000);
   assertNotNull(msg);
   msg = consumer.receive(1000);
   assertNotNull(msg);
   msg.acknowledge();

   // Reset the session.
   session.close();
   session = connection.createSession(false, ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE);

   // Attempt to Consume the message...
   consumer = session.createConsumer(queue);
   msg = consumer.receive(1000);
   assertNotNull(msg);
   assertEquals(msg1, msg);
   msg = consumer.receive(1000);
   assertNotNull(msg);
   assertEquals(msg2, msg);
   msg = consumer.receive(1000);
   assertNull(msg);
   session.close();
}
 
Example #16
Source File: ActiveMQDestinationTestSupport.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void populateObject(Object object) throws Exception {
   super.populateObject(object);
   ActiveMQDestination info = (ActiveMQDestination) object;
   info.setPhysicalName("PhysicalName:1");

}
 
Example #17
Source File: PeerTransportTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected ActiveMQDestination createDestination(String name) {
   if (topic) {
      return new ActiveMQTopic(name);
   } else {
      return new ActiveMQQueue(name);
   }
}
 
Example #18
Source File: JobStream.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 
 * @return A set containing all ActiveMQDestination objects used by this JobStream 
 */
protected Set<ActiveMQDestination> getAllQueues() {
	Set<ActiveMQDestination> ret = new HashSet<>();
	ret.addAll(pre.values());
	ret.addAll(post.values());
	ret.addAll(destination.values());
	return ret;
}
 
Example #19
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 #20
Source File: AdvisoryTopicDeletionTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void doTest() throws Exception {
   Destination dest = createDestination();

   Session producerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Session consumerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

   MessageConsumer consumer = consumerSession.createConsumer(dest);

   MessageProducer prod = producerSession.createProducer(dest);
   Message message = producerSession.createMessage();
   prod.send(message);

   consumer.receive(60 * 1000);
   connection.close();
   connection = null;

   if (topic) {
      broker.getAdminView().removeTopic(((ActiveMQDestination) dest).getPhysicalName());
   } else {
      broker.getAdminView().removeQueue(((ActiveMQDestination) dest).getPhysicalName());
   }

   ActiveMQDestination dests[] = broker.getRegionBroker().getDestinations();
   int matchingDestinations = 0;
   for (ActiveMQDestination destination : dests) {
      String name = destination.getPhysicalName();
      LOG.debug("Found destination " + name);
      if (name.startsWith("ActiveMQ.Advisory") && name.contains(getDestinationString())) {
         matchingDestinations++;
      }
   }

   assertEquals("No matching destinations should be found", 0, matchingDestinations);
}
 
Example #21
Source File: ActiveMQClientITBase.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies traces for when {@link ActiveMQMessageConsumer} consumes the message and dispatches for
 * further processing (for example, calling {@link MessageListener} attached to the consumer directly, or adding
 * the message to {@link org.apache.activemq.MessageDispatchChannel MessageDispatchChannel}.
 *
 * @param verifier verifier used to verify traces
 * @param destination the destination from which the consumer is receiving the message
 * @param session the session established by the consumer
 * @throws Exception
 */
private void verifyConsumerConsumeEvent(PluginTestVerifier verifier, ActiveMQDestination destination, ActiveMQSession session) throws Exception {
    String expectedEndPoint = session.getConnection().getTransport().getRemoteAddress();
    ExpectedTrace activeMQConsumerInvocationTrace = root(ACTIVEMQ_CLIENT, // serviceType
            "ActiveMQ Consumer Invocation", // method
            destination.getQualifiedName(), // rpc
            null, // endPoint (collected but there's no easy way to retrieve local address)
            expectedEndPoint);
    Method dispatchMethod = ActiveMQMessageConsumer.class.getDeclaredMethod("dispatch", MessageDispatch.class);
    ExpectedTrace dispatchTrace = event(ACTIVEMQ_CLIENT_INTERNAL, dispatchMethod);
    verifier.verifyDiscreteTrace(activeMQConsumerInvocationTrace, dispatchTrace);
}
 
Example #22
Source File: JmsTopicWildcardSendReceiveTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void testReceiveWildcardTopicMidAsterisk() throws Exception {
   connection.start();
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

   ActiveMQDestination destination1 = (ActiveMQDestination) session.createTopic(destination1String);
   ActiveMQDestination destination4 = (ActiveMQDestination) session.createTopic(destination4String);

   Message m = null;
   MessageConsumer consumer = null;
   String text = null;

   ActiveMQDestination destination8 = (ActiveMQDestination) session.createTopic("TEST.*.ONE");
   consumer = session.createConsumer(destination8);
   sendMessage(session, destination1, destination1String);
   sendMessage(session, destination4, destination4String);
   m = consumer.receive(1000);
   assertNotNull(m);
   text = ((TextMessage) m).getText();
   if (!(text.equals(destination1String) || text.equals(destination4String))) {
      fail("unexpected message:" + text);
   }
   m = consumer.receive(1000);
   assertNotNull(m);
   text = ((TextMessage) m).getText();
   if (!(text.equals(destination1String) || text.equals(destination4String))) {
      fail("unexpected message:" + text);
   }
   assertNull(consumer.receiveNoWait());

}
 
Example #23
Source File: JmsResourceProvider.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a destination, which can either a topic or a queue.
 *
 * @see org.apache.activemq.test.JmsResourceProvider#createDestination(javax.jms.Session,
 * java.lang.String)
 */
public Destination createDestination(Session session, JmsTransactionTestSupport support) throws JMSException {
   if (isTopic) {
      return support.createDestination(session, ActiveMQDestination.TOPIC_TYPE);
   } else {
      return support.createDestination(session, ActiveMQDestination.QUEUE_TYPE);
   }
}
 
Example #24
Source File: MessageExpirationTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected Message createMessage(ProducerInfo producerInfo,
                                ActiveMQDestination destination,
                                int deliveryMode,
                                int timeToLive) {
   Message message = createMessage(producerInfo, destination, deliveryMode);
   long now = System.currentTimeMillis();
   message.setTimestamp(now);
   message.setExpiration(now + timeToLive);
   return message;
}
 
Example #25
Source File: OpenWireConnection.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Checks to see if this destination exists.  If it does not throw an invalid destination exception.
 *
 * @param destination
 */
private void validateDestination(ActiveMQDestination destination) throws Exception {
   if (destination.isQueue()) {
      SimpleString physicalName = new SimpleString(destination.getPhysicalName());
      BindingQueryResult result = server.bindingQuery(physicalName);
      if (!result.isExists() && !result.isAutoCreateQueues()) {
         throw ActiveMQMessageBundle.BUNDLE.noSuchQueue(physicalName);
      }
   }
}
 
Example #26
Source File: BrokerTestSupport.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected DestinationInfo createTempDestinationInfo(ConnectionInfo connectionInfo, byte destinationType) {
   DestinationInfo info = new DestinationInfo();
   info.setConnectionId(connectionInfo.getConnectionId());
   info.setOperationType(DestinationInfo.ADD_OPERATION_TYPE);
   info.setDestination(ActiveMQDestination.createDestination(info.getConnectionId() + ":" + (++tempDestGenerator), destinationType));
   return info;
}
 
Example #27
Source File: JmsQueueWildcardSendReceiveTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void testReceiveWildcardQueueMidAsterisk() throws Exception {
   connection.start();
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

   ActiveMQDestination destination1 = (ActiveMQDestination) session.createQueue(destination1String);
   ActiveMQDestination destination4 = (ActiveMQDestination) session.createQueue(destination4String);

   Message m = null;
   MessageConsumer consumer = null;
   String text = null;

   sendMessage(session, destination1, destination1String);
   sendMessage(session, destination4, destination4String);
   ActiveMQDestination destination8 = (ActiveMQDestination) session.createQueue("TEST.*.ONE");
   consumer = session.createConsumer(destination8);
   m = consumer.receive(1000);
   assertNotNull(m);
   text = ((TextMessage) m).getText();
   if (!(text.equals(destination1String) || text.equals(destination4String))) {
      fail("unexpected message:" + text);
   }
   m = consumer.receive(1000);
   assertNotNull(m);
   text = ((TextMessage) m).getText();
   if (!(text.equals(destination1String) || text.equals(destination4String))) {
      fail("unexpected message:" + text);
   }
   assertNull(consumer.receiveNoWait());

}
 
Example #28
Source File: AMQSession.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public String convertWildcard(ActiveMQDestination openWireDest) {
   if (openWireDest.isTemporary() || AdvisorySupport.isAdvisoryTopic(openWireDest)) {
      return openWireDest.getPhysicalName();
   } else {
      return OPENWIRE_WILDCARD.convert(openWireDest.getPhysicalName(), server.getConfiguration().getWildcardConfiguration());
   }
}
 
Example #29
Source File: LDAPAuthorizationMapTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testAdvisory() {
   ActiveMQDestination dest = AdvisorySupport.getConnectionAdvisoryTopic();
   Set<GroupPrincipal> acls = authMap.getWriteACLs(dest);

   assertEquals(1, acls.size());
   assertTrue(acls.contains(new GroupPrincipal("role3")));
}
 
Example #30
Source File: ThreeBrokerQueueNetworkTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private void verifyConsumePriority(BrokerService broker, byte expectedPriority, Destination dest) throws Exception {
   RegionBroker regionBroker = (RegionBroker) broker.getRegionBroker();
   Queue internalQueue = (Queue) regionBroker.getDestinations(ActiveMQDestination.transform(dest)).iterator().next();
   for (Subscription consumer : internalQueue.getConsumers()) {
      assertEquals("consumer on " + broker.getBrokerName() + " matches priority: " + internalQueue, expectedPriority, consumer.getConsumerInfo().getPriority());
   }
}