Search in sources :

Example 41 with ActiveMQQueue

use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.

the class DestinationListenerTest method testProducerForcesNotificationOfNewDestination.

public void testProducerForcesNotificationOfNewDestination() throws Exception {
    // now lets cause a destination to be created
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQQueue newQueue = new ActiveMQQueue("Test.Beer");
    MessageProducer producer = session.createProducer(newQueue);
    TextMessage message = session.createTextMessage("<hello>world</hello>");
    producer.send(message);
    Thread.sleep(3000);
    assertThat(newQueue, isIn(newDestinations));
    LOG.info("New destinations are: " + newDestinations);
}
Also used : ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Example 42 with ActiveMQQueue

use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.

the class BrokerBenchmark method initCombosForTestPerformance.

public void initCombosForTestPerformance() {
    addCombinationValues("destination", new Object[] { new ActiveMQQueue("TEST"), new ActiveMQTopic("TEST") });
    addCombinationValues("PRODUCER_COUNT", new Object[] { new Integer("1"), new Integer("10") });
    addCombinationValues("CONSUMER_COUNT", new Object[] { new Integer("1"), new Integer("10") });
    addCombinationValues("CONSUMER_COUNT", new Object[] { new Integer("1"), new Integer("10") });
    addCombinationValues("deliveryMode", new Object[] { Boolean.TRUE });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue)

Example 43 with ActiveMQQueue

use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.

the class JmsMultipleClientsTestSupport method createDestination.

protected ActiveMQDestination createDestination() throws JMSException {
    String name = "." + getClass().getName() + "." + getName();
    // ensure not inadvertently composite because of combos
    name = name.replace(' ', '_');
    name = name.replace(',', '&');
    if (topic) {
        destination = new ActiveMQTopic("Topic" + name);
        return (ActiveMQDestination) destination;
    } else {
        destination = new ActiveMQQueue("Queue" + name);
        return (ActiveMQDestination) destination;
    }
}
Also used : ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 44 with ActiveMQQueue

use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.

the class JmsQueueBrowserTest method testReceiveBrowseReceive.

/**
 * Tests the queue browser. Browses the messages then the consumer tries to receive them. The messages should still
 * be in the queue even when it was browsed.
 *
 * @throws Exception
 */
public void testReceiveBrowseReceive() throws Exception {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQQueue destination = new ActiveMQQueue("TEST");
    MessageProducer producer = session.createProducer(destination);
    MessageConsumer consumer = session.createConsumer(destination);
    connection.start();
    Message[] outbound = new Message[] { session.createTextMessage("First Message"), session.createTextMessage("Second Message"), session.createTextMessage("Third Message") };
    // lets consume any outstanding messages from previous test runs
    while (consumer.receive(1000) != null) {
    }
    producer.send(outbound[0]);
    producer.send(outbound[1]);
    producer.send(outbound[2]);
    // Get the first.
    assertEquals(outbound[0], consumer.receive(1000));
    consumer.close();
    QueueBrowser browser = session.createBrowser(destination);
    Enumeration<?> enumeration = browser.getEnumeration();
    // browse the second
    assertTrue("should have received the second message", enumeration.hasMoreElements());
    assertEquals(outbound[1], enumeration.nextElement());
    // browse the third.
    assertTrue("Should have received the third message", enumeration.hasMoreElements());
    assertEquals(outbound[2], enumeration.nextElement());
    // There should be no more.
    boolean tooMany = false;
    while (enumeration.hasMoreElements()) {
        LOG.info("Got extra message: " + ((TextMessage) enumeration.nextElement()).getText());
        tooMany = true;
    }
    assertFalse(tooMany);
    browser.close();
    // Re-open the consumer.
    consumer = session.createConsumer(destination);
    // Receive the second.
    assertEquals(outbound[1], consumer.receive(1000));
    // Receive the third.
    assertEquals(outbound[2], consumer.receive(1000));
    consumer.close();
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) QueueBrowser(javax.jms.QueueBrowser) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Example 45 with ActiveMQQueue

use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.

the class JmsQueueBrowserTest method testLargeNumberOfMessages.

public void testLargeNumberOfMessages() throws Exception {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQQueue destination = new ActiveMQQueue("TEST");
    connection.start();
    MessageProducer producer = session.createProducer(destination);
    int numberOfMessages = 4096;
    for (int i = 0; i < numberOfMessages; i++) {
        producer.send(session.createTextMessage("Message: " + i));
    }
    QueueBrowser browser = session.createBrowser(destination);
    Enumeration<?> enumeration = browser.getEnumeration();
    assertTrue(enumeration.hasMoreElements());
    int numberBrowsed = 0;
    while (enumeration.hasMoreElements()) {
        Message browsed = (Message) enumeration.nextElement();
        if (LOG.isDebugEnabled()) {
            LOG.debug("Browsed Message [{}]", browsed.getJMSMessageID());
        }
        numberBrowsed++;
    }
    System.out.println("Number browsed:  " + numberBrowsed);
    assertEquals(numberOfMessages, numberBrowsed);
    browser.close();
    producer.close();
}
Also used : TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) QueueBrowser(javax.jms.QueueBrowser) Session(javax.jms.Session)

Aggregations

ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)239 Session (javax.jms.Session)81 MessageProducer (javax.jms.MessageProducer)78 MessageConsumer (javax.jms.MessageConsumer)76 TextMessage (javax.jms.TextMessage)73 Test (org.junit.Test)66 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)54 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)44 Message (javax.jms.Message)36 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)33 Connection (javax.jms.Connection)32 Destination (javax.jms.Destination)27 CountDownLatch (java.util.concurrent.CountDownLatch)20 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)18 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)18 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)18 SessionInfo (org.apache.activemq.command.SessionInfo)18 Message (org.apache.activemq.command.Message)17 BasicOpenWireTest (org.apache.activemq.artemis.tests.integration.openwire.BasicOpenWireTest)16 ProducerInfo (org.apache.activemq.command.ProducerInfo)16