org.apache.activemq.artemis.jms.client.ActiveMQTopic

Here are the examples of the java api class org.apache.activemq.artemis.jms.client.ActiveMQTopic taken from open source projects.

1. JMSServerManagerImpl#addTopicToBindingRegistry()

View license
@Override
public boolean addTopicToBindingRegistry(final String topicName, final String registryBinding) throws Exception {
    checkInitialised();
    checkBindings(registryBinding);
    ActiveMQTopic destination = topics.get(topicName);
    if (destination == null) {
        throw new IllegalArgumentException("Topic does not exist");
    }
    if (destination.getTopicName() == null) {
        throw new IllegalArgumentException(topicName + " is not a topic");
    }
    boolean added = bindToBindings(registryBinding, destination);
    if (added) {
        addToBindings(topicBindings, topicName, registryBinding);
        storage.addBindings(PersistedType.Topic, topicName, registryBinding);
    }
    return added;
}

2. TopicControlTest#testListSubscriptionsAsJSONWithHierarchicalTopics()

View license
@Test
public void testListSubscriptionsAsJSONWithHierarchicalTopics() throws Exception {
    serverManager.createTopic(false, "my.jms.#", "jms/all");
    serverManager.createTopic(false, "my.jms.A", "jms/A");
    ActiveMQTopic myTopic = (ActiveMQTopic) ActiveMQJMSClient.createTopic("my.jms.A");
    TopicControl topicControl = ManagementControlHelper.createTopicControl(myTopic, mbeanServer);
    String jsonString = topicControl.listDurableSubscriptionsAsJSON();
    SubscriptionInfo[] infos = SubscriptionInfo.from(jsonString);
    Assert.assertEquals(1, infos.length);
    Assert.assertEquals("ActiveMQ", infos[0].getClientID());
    Assert.assertEquals("ActiveMQ", infos[0].getName());
}

3. ReferenceableTest#testReferenceTopic()

View license
@Test
public void testReferenceTopic() throws Exception {
    Reference topicRef = ((Referenceable) ActiveMQServerTestCase.topic1).getReference();
    String factoryName = topicRef.getFactoryClassName();
    Class factoryClass = Class.forName(factoryName);
    DestinationObjectFactory factory = (DestinationObjectFactory) factoryClass.newInstance();
    Object instance = factory.getObjectInstance(topicRef, null, null, null);
    ProxyAssertSupport.assertTrue(instance instanceof ActiveMQDestination);
    ActiveMQTopic topic2 = (ActiveMQTopic) instance;
    ProxyAssertSupport.assertEquals(ActiveMQServerTestCase.topic1.getTopicName(), topic2.getTopicName());
    simpleSendReceive(cf, topic2);
}

4. TopicCleanupTest#testWildcardSubscriber()

View license
@Test
public void testWildcardSubscriber() throws Exception {
    ActiveMQTopic topic = (ActiveMQTopic) createTopic("topic.A");
    Connection conn = cf.createConnection();
    conn.start();
    try {
        Session consumerStarSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumerStar = consumerStarSession.createConsumer(ActiveMQJMSClient.createTopic("topic.*"));
        Session consumerASession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumerA = consumerASession.createConsumer(topic);
        Session producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producerA = producerSession.createProducer(topic);
        TextMessage msg1 = producerSession.createTextMessage("text");
        producerA.send(msg1);
        consumerStar.close();
        consumerA.close();
        producerA.send(msg1);
        conn.close();
        boolean foundStrayRoutingBinding = false;
        Bindings bindings = server.getPostOffice().getBindingsForAddress(new SimpleString(topic.getAddress()));
        Map<SimpleString, List<Binding>> routingNames = ((BindingsImpl) bindings).getRoutingNameBindingMap();
        for (SimpleString key : routingNames.keySet()) {
            if (!key.toString().equals(topic.getAddress())) {
                foundStrayRoutingBinding = true;
                assertEquals(0, ((LocalQueueBinding) routingNames.get(key).get(0)).getQueue().getMessageCount());
            }
        }
        assertFalse(foundStrayRoutingBinding);
    } finally {
        jmsServer.stop();
        jmsServer.start();
        try {
            conn.close();
        } catch (Throwable igonred) {
        }
    }
}

5. JMSQueueControlTest#createTestTopicWithDLQ()

View license
protected ActiveMQTopic createTestTopicWithDLQ(final String queueName, final ActiveMQQueue dlq) throws Exception {
    serverManager.createTopic(false, queueName);
    ActiveMQTopic testQueue = (ActiveMQTopic) ActiveMQJMSClient.createTopic(queueName);
    AddressSettings addressSettings = new AddressSettings();
    addressSettings.setDeadLetterAddress(new SimpleString(dlq.getAddress()));
    addressSettings.setMaxDeliveryAttempts(1);
    server.getAddressSettingsRepository().addMatch(testQueue.getAddress(), addressSettings);
    return testQueue;
}

6. JMSQueueControlTest#testRetryMessagesOnTopic()

View license
/**
    * Test retrying all messages put on DLQ - i.e. they should appear on the original queue.
    * @throws Exception
    */
@Test
public void testRetryMessagesOnTopic() throws Exception {
    ActiveMQQueue dlq = createDLQ(RandomUtil.randomString());
    ActiveMQTopic testTopic = createTestTopicWithDLQ(RandomUtil.randomString(), dlq);
    Connection connectionConsume = createConnection();
    connectionConsume.setClientID("ID");
    Session sessionConsume = connectionConsume.createSession(true, Session.SESSION_TRANSACTED);
    MessageConsumer cons1 = sessionConsume.createDurableSubscriber(testTopic, "sub1");
    MessageConsumer cons2 = sessionConsume.createDurableSubscriber(testTopic, "sub2");
    final int numMessagesToTest = 10;
    JMSUtil.sendMessages(testTopic, numMessagesToTest);
    connectionConsume.start();
    for (int i = 0; i < numMessagesToTest; i++) {
        Assert.assertNotNull(cons1.receive(500));
    }
    sessionConsume.commit();
    Assert.assertNull(cons1.receiveNoWait());
    connectionConsume.start();
    for (int i = 0; i < numMessagesToTest; i++) {
        cons2.receive(500);
    }
    sessionConsume.rollback();
    Assert.assertNull(cons2.receiveNoWait());
    JMSQueueControl dlqQueueControl = createManagementControl(dlq);
    dlqQueueControl.retryMessages();
    Assert.assertNull("Retry is sending back to cons1 even though it succeeded", cons1.receiveNoWait());
    for (int i = 0; i < numMessagesToTest; i++) {
        Assert.assertNotNull(cons2.receive(500));
    }
    sessionConsume.commit();
    Assert.assertNull(cons1.receiveNoWait());
    connectionConsume.close();
}