Search in sources :

Example 66 with ActiveMQQueue

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

the class VerySimpleOenwireTest method testOpenWireExample.

/**
 * This is the example shipped with the distribution
 *
 * @throws Exception
 */
@Test
public void testOpenWireExample() throws Exception {
    Connection exConn = null;
    SimpleString durableQueue = new SimpleString("exampleQueue");
    this.server.createQueue(durableQueue, RoutingType.ANYCAST, durableQueue, null, true, false, -1, false, true);
    try {
        ActiveMQConnectionFactory exFact = new ActiveMQConnectionFactory();
        Queue queue = new ActiveMQQueue("exampleQueue");
        exConn = exFact.createConnection();
        exConn.start();
        Session session = exConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer(queue);
        TextMessage message = session.createTextMessage("This is a text message");
        producer.send(message);
        MessageConsumer messageConsumer = session.createConsumer(queue);
        TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
        assertEquals("This is a text message", messageReceived.getText());
    } finally {
        if (exConn != null) {
            exConn.close();
        }
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 67 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
 */
@Test
public void testReceiveBrowseReceive() throws Exception {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQQueue destination = (ActiveMQQueue) this.createDestination(session, ActiveMQDestination.QUEUE_TYPE);
    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();
    System.out.println("creating browser...");
    QueueBrowser browser = session.createBrowser(destination);
    System.out.println("browser created");
    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()) {
        System.out.println("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) BasicOpenWireTest(org.apache.activemq.artemis.tests.integration.openwire.BasicOpenWireTest) Test(org.junit.Test)

Example 68 with ActiveMQQueue

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

the class JmsQueueBrowserTest method testBatchSendBrowseReceive.

@Test
public void testBatchSendBrowseReceive() throws Exception {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQQueue destination = (ActiveMQQueue) this.createDestination(session, ActiveMQDestination.QUEUE_TYPE);
    MessageProducer producer = session.createProducer(destination);
    MessageConsumer consumer = session.createConsumer(destination);
    connection.start();
    TextMessage[] outbound = new TextMessage[10];
    for (int i = 0; i < 10; i++) {
        outbound[i] = session.createTextMessage(i + " Message");
    }
    // lets consume any outstanding messages from previous test runs
    while (consumer.receive(1000) != null) {
    }
    consumer.close();
    for (int i = 0; i < outbound.length; i++) {
        producer.send(outbound[i]);
    }
    QueueBrowser browser = session.createBrowser(destination);
    Enumeration<?> enumeration = browser.getEnumeration();
    for (int i = 0; i < outbound.length; i++) {
        assertTrue("should have a", enumeration.hasMoreElements());
        assertEquals(outbound[i], enumeration.nextElement());
    }
    browser.close();
    for (int i = 0; i < outbound.length; i++) {
        producer.send(outbound[i]);
    }
    // verify second batch is visible to browse
    browser = session.createBrowser(destination);
    enumeration = browser.getEnumeration();
    for (int j = 0; j < 2; j++) {
        for (int i = 0; i < outbound.length; i++) {
            assertTrue("should have a", enumeration.hasMoreElements());
            assertEquals("j=" + j + ", i=" + i, outbound[i].getText(), ((TextMessage) enumeration.nextElement()).getText());
        }
    }
    browser.close();
    consumer = session.createConsumer(destination);
    for (int i = 0; i < outbound.length * 2; i++) {
        assertNotNull("Got message: " + i, consumer.receive(2000));
    }
    consumer.close();
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) QueueBrowser(javax.jms.QueueBrowser) Session(javax.jms.Session) BasicOpenWireTest(org.apache.activemq.artemis.tests.integration.openwire.BasicOpenWireTest) Test(org.junit.Test)

Example 69 with ActiveMQQueue

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

the class AbstractCachedLDAPAuthorizationMapLegacyTest method testSynchronousUpdate.

@Test
public void testSynchronousUpdate() throws Exception {
    map.setRefreshInterval(1);
    map.query();
    Set<?> readACLs = map.getReadACLs(new ActiveMQQueue("TEST.FOO"));
    assertEquals("set size: " + readACLs, 2, readACLs.size());
    assertTrue("Contains admin group", readACLs.contains(ADMINS));
    assertTrue("Contains users group", readACLs.contains(USERS));
    Set<?> failedACLs = map.getReadACLs(new ActiveMQQueue("FAILED"));
    assertEquals("set size: " + failedACLs, 0, failedACLs.size());
    LdifReader reader = new LdifReader(getRemoveLdif());
    for (LdifEntry entry : reader) {
        connection.delete(entry.getDn());
    }
    reader.close();
    assertTrue("did not get expected size. ", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return map.getReadACLs(new ActiveMQQueue("TEST.FOO")).size() == 0;
        }
    }));
    assertNull(map.getTempDestinationReadACLs());
    assertNull(map.getTempDestinationWriteACLs());
    assertNull(map.getTempDestinationAdminACLs());
}
Also used : LdifReader(org.apache.directory.shared.ldap.model.ldif.LdifReader) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) LdifEntry(org.apache.directory.shared.ldap.model.ldif.LdifEntry) Test(org.junit.Test)

Example 70 with ActiveMQQueue

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

the class AbstractCachedLDAPAuthorizationMapLegacyTest method testAdd.

@Test
public void testAdd() throws Exception {
    map.query();
    Set<?> failedACLs = map.getReadACLs(new ActiveMQQueue("FAILED"));
    assertEquals("set size: " + failedACLs, 0, failedACLs.size());
    LdifReader reader = new LdifReader(getAddLdif());
    for (LdifEntry entry : reader) {
        connection.add(entry.getEntry());
    }
    reader.close();
    Thread.sleep(2000);
    failedACLs = map.getReadACLs(new ActiveMQQueue("FAILED"));
    assertEquals("set size: " + failedACLs, 2, failedACLs.size());
}
Also used : LdifReader(org.apache.directory.shared.ldap.model.ldif.LdifReader) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) LdifEntry(org.apache.directory.shared.ldap.model.ldif.LdifEntry) Test(org.junit.Test)

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