Search in sources :

Example 16 with TemporaryQueue

use of javax.jms.TemporaryQueue in project activemq-artemis by apache.

the class AdvisoryTempDestinationTests method testMessageDeliveryAdvisory.

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);
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) BytesMessage(javax.jms.BytesMessage) Message(javax.jms.Message) TemporaryQueue(javax.jms.TemporaryQueue) BytesMessage(javax.jms.BytesMessage) MessageProducer(javax.jms.MessageProducer) Topic(javax.jms.Topic) Session(javax.jms.Session)

Example 17 with TemporaryQueue

use of javax.jms.TemporaryQueue in project activemq-artemis by apache.

the class TempDestLoadTest method testLoadTempAdvisoryQueues.

public void testLoadTempAdvisoryQueues() throws Exception {
    for (int i = 0; i < MESSAGE_COUNT; i++) {
        TemporaryQueue tempQueue = session.createTemporaryQueue();
        MessageConsumer consumer = session.createConsumer(tempQueue);
        MessageProducer producer = session.createProducer(tempQueue);
        consumer.close();
        producer.close();
        tempQueue.delete();
    }
    AdvisoryBroker ab = (AdvisoryBroker) broker.getBroker().getAdaptor(AdvisoryBroker.class);
    assertTrue(ab.getAdvisoryDestinations().size() == 0);
    assertTrue(ab.getAdvisoryConsumers().size() == 0);
    assertTrue(ab.getAdvisoryProducers().size() == 0);
    RegionBroker rb = (RegionBroker) broker.getBroker().getAdaptor(RegionBroker.class);
    for (Destination dest : rb.getDestinationMap().values()) {
        LOG.debug("Destination: {}", dest);
    }
    // there should be at least 2 destinations - advisories -
    // 1 for the connection + 1 generic ones
    assertTrue("Should be at least 2 destinations", rb.getDestinationMap().size() > 2);
}
Also used : Destination(org.apache.activemq.broker.region.Destination) MessageConsumer(javax.jms.MessageConsumer) RegionBroker(org.apache.activemq.broker.region.RegionBroker) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer)

Example 18 with TemporaryQueue

use of javax.jms.TemporaryQueue in project activemq-artemis by apache.

the class JMSTemporaryDestinationTest method testCreateTemporaryQueue.

@Test(timeout = 60000)
public void testCreateTemporaryQueue() throws Throwable {
    Connection connection = createConnection();
    try {
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        TemporaryQueue queue = session.createTemporaryQueue();
        System.out.println("queue:" + queue.getQueueName());
        MessageProducer producer = session.createProducer(queue);
        TextMessage message = session.createTextMessage();
        message.setText("Message temporary");
        producer.send(message);
        MessageConsumer consumer = session.createConsumer(queue);
        connection.start();
        message = (TextMessage) consumer.receive(5000);
        assertNotNull(message);
    } finally {
        connection.close();
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 19 with TemporaryQueue

use of javax.jms.TemporaryQueue in project activemq-artemis by apache.

the class JMSMessageProducerTest method testReplyToUsingQueue.

@Test(timeout = 60000)
public void testReplyToUsingQueue() throws Throwable {
    Connection connection = createConnection();
    try {
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        TemporaryQueue queue = session.createTemporaryQueue();
        MessageProducer p = session.createProducer(queue);
        TextMessage message = session.createTextMessage();
        message.setText("Message temporary");
        message.setJMSReplyTo(session.createQueue(getQueueName()));
        p.send(message);
        MessageConsumer cons = session.createConsumer(queue);
        connection.start();
        message = (TextMessage) cons.receive(5000);
        assertNotNull(message);
        Destination jmsReplyTo = message.getJMSReplyTo();
        assertNotNull(jmsReplyTo);
        assertNotNull(message);
    } finally {
        connection.close();
    }
}
Also used : Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 20 with TemporaryQueue

use of javax.jms.TemporaryQueue in project activemq-artemis by apache.

the class JMSMessageProducerTest method testReplyToUsingTempQueue.

@Test(timeout = 60000)
public void testReplyToUsingTempQueue() throws Throwable {
    Connection connection = createConnection();
    try {
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        TemporaryQueue queue = session.createTemporaryQueue();
        MessageProducer p = session.createProducer(queue);
        TextMessage message = session.createTextMessage();
        message.setText("Message temporary");
        message.setJMSReplyTo(session.createTemporaryQueue());
        p.send(message);
        MessageConsumer cons = session.createConsumer(queue);
        connection.start();
        message = (TextMessage) cons.receive(5000);
        Destination jmsReplyTo = message.getJMSReplyTo();
        assertNotNull(jmsReplyTo);
        assertNotNull(message);
    } finally {
        connection.close();
    }
}
Also used : Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

TemporaryQueue (javax.jms.TemporaryQueue)91 Session (javax.jms.Session)56 Test (org.junit.Test)47 Connection (javax.jms.Connection)45 MessageProducer (javax.jms.MessageProducer)38 MessageConsumer (javax.jms.MessageConsumer)35 Message (javax.jms.Message)27 JMSException (javax.jms.JMSException)25 TextMessage (javax.jms.TextMessage)24 JMSContext (javax.jms.JMSContext)13 BytesMessage (javax.jms.BytesMessage)10 Destination (javax.jms.Destination)8 Queue (javax.jms.Queue)8 ConnectionFactory (javax.jms.ConnectionFactory)7 ObjectMessage (javax.jms.ObjectMessage)7 JMSConsumer (javax.jms.JMSConsumer)6 TemporaryTopic (javax.jms.TemporaryTopic)6 HashMap (java.util.HashMap)5 MapMessage (javax.jms.MapMessage)5 StreamMessage (javax.jms.StreamMessage)5