javax.jms.Destination

Here are the examples of the java api class javax.jms.Destination taken from open source projects.

1. JmsProxyImplTest#setUp()

Project: c2mon
File: JmsProxyImplTest.java
@Before
public void setUp() {
    connectionFactory = EasyMock.createNiceMock(ConnectionFactory.class);
    connection = EasyMock.createNiceMock(Connection.class);
    session = EasyMock.createNiceMock(Session.class);
    Destination supervisionTopic = EasyMock.createNiceMock(Destination.class);
    Destination heartbeatTopic = EasyMock.createNiceMock(Destination.class);
    Destination alarmTopic = EasyMock.createNiceMock(Destination.class);
    SlowConsumerListener slowConsumerListener = EasyMock.createNiceMock(SlowConsumerListener.class);
    jmsProxy = new JmsProxyImpl(connectionFactory, supervisionTopic, alarmTopic, heartbeatTopic, slowConsumerListener);
}

2. JMSDestinationTest#sendReceive()

Project: qpid-java
File: JMSDestinationTest.java
private void sendReceive(String address) throws JMSException, Exception {
    Destination dest = _session.createQueue(address);
    MessageConsumer consumer = _session.createConsumer(dest);
    _connection.start();
    sendMessage(_session, dest, 1);
    Message receivedMessage = consumer.receive(10000);
    assertNotNull("Message should not be null", receivedMessage);
    Destination receivedDestination = receivedMessage.getJMSDestination();
    assertNotNull("JMSDestination should not be null", receivedDestination);
    assertEquals("JMSDestination should match that sent", address, receivedDestination.toString());
}

3. AddressBasedDestinationTest#replyToTest()

Project: qpid-java
File: AddressBasedDestinationTest.java
private void replyToTest(String replyTo) throws Exception {
    Session session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination replyToDest = AMQDestination.createDestination(replyTo, false);
    MessageConsumer replyToCons = session.createConsumer(replyToDest);
    Destination dest = session.createQueue("ADDR:amq.direct/test");
    MessageConsumer cons = session.createConsumer(dest);
    MessageProducer prod = session.createProducer(dest);
    Message m = session.createTextMessage("test");
    m.setJMSReplyTo(replyToDest);
    prod.send(m);
    Message msg = cons.receive(5000l);
    MessageProducer prodR = session.createProducer(msg.getJMSReplyTo());
    prodR.send(session.createTextMessage("x"));
    Message m1 = replyToCons.receive(5000l);
    assertNotNull("The reply to consumer should have received the messsage", m1);
}

4. AMQMessageDelegate_0_10Test#testDestinationCache()

Project: qpid-java
File: AMQMessageDelegate_0_10Test.java
/**
     * Tests that when two messages arrive with the same ReplyTo exchange and routingKey values,
     * the cache returns the same Destination object from getJMSReplyTo instead of a new one.
     */
public void testDestinationCache() throws Exception {
    //create a message delegate and retrieve the replyTo Destination
    AMQMessageDelegate_0_10 delegate1 = generateMessageDelegateWithReplyTo();
    Destination dest1 = delegate1.getJMSReplyTo();
    //create a new message delegate with the same details, and retrieve the replyTo Destination
    AMQMessageDelegate_0_10 delegate2 = generateMessageDelegateWithReplyTo();
    Destination dest2 = delegate2.getJMSReplyTo();
    //verify that the destination cache means these are the same Destination object
    assertSame("Should have received the same Destination objects", dest1, dest2);
}

5. JmsRollbackRedeliveryTest#populateDestinationWithInterleavedProducer()

Project: activemq-artemis
File: JmsRollbackRedeliveryTest.java
private void populateDestinationWithInterleavedProducer(final int nbMessages, final String destinationName, Connection connection) throws JMSException {
    Session session1 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination1 = session1.createQueue(destinationName);
    MessageProducer producer1 = session1.createProducer(destination1);
    Session session2 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination2 = session2.createQueue(destinationName);
    MessageProducer producer2 = session2.createProducer(destination2);
    for (int i = 1; i <= nbMessages; i++) {
        if (i % 2 == 0) {
            producer1.send(session1.createTextMessage("<hello id='" + i + "'/>"));
        } else {
            producer2.send(session2.createTextMessage("<hello id='" + i + "'/>"));
        }
    }
    producer1.close();
    session1.close();
    producer2.close();
    session2.close();
}

6. JmsAdapterTests#createAdapter()

Project: spring-flex
File: JmsAdapterTests.java
private JmsAdapter createAdapter() throws Exception {
    String adapterBeanName = "test-jms-adapter";
    MutablePropertyValues properties = new MutablePropertyValues();
    ConnectionFactory cf = new ActiveMQConnectionFactory("vm:(broker:(tcp://localhost:61616)?persistent=false)?marshal=false");
    Destination dest = new ActiveMQTopic("test.topic");
    properties.addPropertyValue("connectionFactory", cf);
    properties.addPropertyValue("jmsDestination", dest);
    StaticApplicationContext context = new StaticApplicationContext();
    context.registerPrototype(adapterBeanName, JmsAdapter.class, properties);
    JmsAdapter adapter = (JmsAdapter) context.getBean(adapterBeanName);
    MessageDestination destination = new MessageDestination();
    destination.setId(DEST_ID);
    destination.setService(getMessageService());
    adapter.setDestination(destination);
    adapter.setApplicationEventPublisher(publisher);
    adapter.start();
    return adapter;
}

7. JmsMessageIntegrityTest#testMapMessage()

Project: qpid-jms
File: JmsMessageIntegrityTest.java
@Test
public void testMapMessage() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = session.createQueue(name.getMethodName());
    MessageConsumer consumer = session.createConsumer(destination);
    MessageProducer producer = session.createProducer(destination);
    {
        MapMessage message = session.createMapMessage();
        message.setBoolean("boolKey", true);
        producer.send(message);
    }
    {
        MapMessage message = (MapMessage) consumer.receive(3000);
        assertNotNull(message);
        assertTrue(message.getBoolean("boolKey"));
    }
    assertNull(consumer.receiveNoWait());
}

8. JmsMessageIntegrityTest#testObjectMessage()

Project: qpid-jms
File: JmsMessageIntegrityTest.java
@Test
public void testObjectMessage() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = session.createQueue(name.getMethodName());
    MessageConsumer consumer = session.createConsumer(destination);
    MessageProducer producer = session.createProducer(destination);
    UUID payload = UUID.randomUUID();
    {
        ObjectMessage message = session.createObjectMessage();
        message.setObject(payload);
        producer.send(message);
    }
    {
        ObjectMessage message = (ObjectMessage) consumer.receive(3000);
        assertNotNull(message);
        assertEquals(payload, message.getObject());
    }
    assertNull(consumer.receiveNoWait());
}

9. JmsMessageIntegrityTest#testBytesMessageLength()

Project: qpid-jms
File: JmsMessageIntegrityTest.java
@Test
public void testBytesMessageLength() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = session.createQueue(name.getMethodName());
    MessageConsumer consumer = session.createConsumer(destination);
    MessageProducer producer = session.createProducer(destination);
    {
        BytesMessage message = session.createBytesMessage();
        message.writeInt(1);
        message.writeInt(2);
        message.writeInt(3);
        message.writeInt(4);
        producer.send(message);
    }
    {
        BytesMessage message = (BytesMessage) consumer.receive(3000);
        assertNotNull(message);
        assertEquals(16, message.getBodyLength());
    }
    assertNull(consumer.receiveNoWait());
}

10. JmsMessageIntegrityTest#testTextMessage()

Project: qpid-jms
File: JmsMessageIntegrityTest.java
@Test
public void testTextMessage() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = session.createQueue(name.getMethodName());
    MessageConsumer consumer = session.createConsumer(destination);
    MessageProducer producer = session.createProducer(destination);
    {
        TextMessage message = session.createTextMessage();
        message.setText("Hi");
        producer.send(message);
    }
    {
        TextMessage message = (TextMessage) consumer.receive(3000);
        assertNotNull(message);
        assertEquals("Hi", message.getText());
    }
    assertNull(consumer.receiveNoWait());
}

11. TransactedProducerSendRateTest#testSendNonPersistentQueueMessagesOpenWire()

Project: qpid-jms
File: TransactedProducerSendRateTest.java
@Test
public void testSendNonPersistentQueueMessagesOpenWire() throws Exception {
    connection = createActiveMQConnection();
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    Destination destination = session.createQueue(getDestinationName());
    MessageProducer producer = session.createProducer(destination);
    producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
    QueueViewMBean queueView = getProxyToQueue(getDestinationName());
    // Warm
    produceMessages(session, producer);
    long totalCycleTime = 0;
    for (int i = 0; i < ITERATIONS; i++) {
        totalCycleTime += produceMessages(session, producer);
        queueView.purge();
    }
    long smoothedTime = totalCycleTime / ITERATIONS;
    LOG.info("Total time for ActiveMQ client = {}", TimeUnit.NANOSECONDS.toMillis(smoothedTime));
}

12. TransactedProducerSendRateTest#testSendNonPersistentQueueMessagesAMQP()

Project: qpid-jms
File: TransactedProducerSendRateTest.java
@Test
public void testSendNonPersistentQueueMessagesAMQP() throws Exception {
    connection = createAmqpConnection();
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    Destination destination = session.createQueue(getDestinationName());
    MessageProducer producer = session.createProducer(destination);
    QueueViewMBean queueView = getProxyToQueue(getDestinationName());
    // Warm
    produceMessages(session, producer);
    long totalCycleTime = 0;
    for (int i = 0; i < ITERATIONS; i++) {
        totalCycleTime += produceMessages(session, producer);
        queueView.purge();
    }
    long smoothedTime = totalCycleTime / ITERATIONS;
    LOG.info("Total time for QPid client = {}", TimeUnit.NANOSECONDS.toMillis(smoothedTime));
}

13. TransactedProducerSendRateTest#testSendNonPersistentTopicMessagesOpenWire()

Project: qpid-jms
File: TransactedProducerSendRateTest.java
@Test
public void testSendNonPersistentTopicMessagesOpenWire() throws Exception {
    connection = createActiveMQConnection();
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    Destination destination = session.createTopic(getDestinationName());
    MessageProducer producer = session.createProducer(destination);
    producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
    // Warm
    produceMessages(session, producer);
    long totalCycleTime = 0;
    for (int i = 0; i < ITERATIONS; i++) {
        totalCycleTime += produceMessages(session, producer);
    }
    long smoothedTime = totalCycleTime / ITERATIONS;
    LOG.info("Total time for ActiveMQ client = {}", TimeUnit.NANOSECONDS.toMillis(smoothedTime));
}

14. TransactedProducerSendRateTest#testSendNonPersistentTopicMessagesAMQP()

Project: qpid-jms
File: TransactedProducerSendRateTest.java
@Test
public void testSendNonPersistentTopicMessagesAMQP() throws Exception {
    connection = createAmqpConnection();
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    Destination destination = session.createTopic(getDestinationName());
    MessageProducer producer = session.createProducer(destination);
    // Warm
    produceMessages(session, producer);
    long totalCycleTime = 0;
    for (int i = 0; i < ITERATIONS; i++) {
        totalCycleTime += produceMessages(session, producer);
    }
    long smoothedTime = totalCycleTime / ITERATIONS;
    LOG.info("Total time for QPid client = {}", TimeUnit.NANOSECONDS.toMillis(smoothedTime));
}

15. FailoverProviderTest#testProducerLifeCyclePassthrough()

Project: qpid-jms
File: FailoverProviderTest.java
@Test(timeout = 30000)
public void testProducerLifeCyclePassthrough() throws Exception {
    JmsConnectionFactory factory = new JmsConnectionFactory("failover:(mock://localhost)");
    Connection connection = factory.createConnection();
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = session.createTopic(_testName.getMethodName());
    session.createProducer(destination).close();
    connection.close();
    assertEquals(1, mockPeer.getContextStats().getCreateResourceCalls(JmsProducerInfo.class));
    assertEquals(1, mockPeer.getContextStats().getDestroyResourceCalls(JmsProducerInfo.class));
}

16. FailoverProviderTest#testConsumerLifeCyclePassthrough()

Project: qpid-jms
File: FailoverProviderTest.java
@Test(timeout = 30000)
public void testConsumerLifeCyclePassthrough() throws Exception {
    JmsConnectionFactory factory = new JmsConnectionFactory("failover:(mock://localhost)");
    Connection connection = factory.createConnection();
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = session.createTopic(_testName.getMethodName());
    session.createConsumer(destination).close();
    connection.close();
    assertEquals(1, mockPeer.getContextStats().getCreateResourceCalls(JmsConsumerInfo.class));
    assertEquals(1, mockPeer.getContextStats().getStartResourceCalls(JmsConsumerInfo.class));
    assertEquals(1, mockPeer.getContextStats().getDestroyResourceCalls(JmsConsumerInfo.class));
}

17. QpidSend#main()

Project: qpid-java
File: QpidSend.java
public static void main(String[] args) throws Exception {
    TestConfiguration config = new JVMArgConfiguration();
    Reporter reporter = new BasicReporter(Throughput.class, System.out, config.reportEvery(), config.isReportHeader());
    Destination dest = AMQDestination.createDestination(config.getAddress(), false);
    QpidSend sender = new QpidSend(reporter, config, config.createConnection(), dest);
    sender.setUp();
    sender.send();
    if (config.getSendEOS() > 0) {
        sender.sendEndMessage();
    }
    if (config.isReportTotal()) {
        reporter.report();
    }
    sender.tearDown();
}

18. QpidReceive#main()

Project: qpid-java
File: QpidReceive.java
public static void main(String[] args) throws Exception {
    TestConfiguration config = new JVMArgConfiguration();
    Reporter reporter = new BasicReporter(ThroughputAndLatency.class, System.out, config.reportEvery(), config.isReportHeader());
    Destination dest = AMQDestination.createDestination(config.getAddress(), false);
    QpidReceive receiver = new QpidReceive(reporter, config, config.createConnection(), dest);
    receiver.setUp();
    receiver.waitforCompletion(config.getMsgCount() + config.getSendEOS());
    if (config.isReportTotal()) {
        reporter.report();
    }
    receiver.tearDown();
}

19. MemoryConsumptionTestClient#ensureQueueCreated()

Project: qpid-java
File: MemoryConsumptionTestClient.java
private Destination ensureQueueCreated(String queueURL, ConnectionFactory connectionFactory) throws JMSException {
    Connection connection = connectionFactory.createConnection();
    Destination destination = null;
    try {
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        destination = session.createQueue(queueURL);
        MessageConsumer consumer = session.createConsumer(destination);
        consumer.close();
        session.close();
    } finally {
        connection.close();
    }
    return destination;
}

20. UTF8Test#runTest()

Project: qpid-java
File: UTF8Test.java
private void runTest(String exchangeName, String queueName, String routingKey, String data) throws Exception {
    Connection con = getConnection();
    Session sess = con.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
    final Destination dest = getDestination(exchangeName, routingKey, queueName);
    final MessageConsumer msgCons = sess.createConsumer(dest);
    con.start();
    // Send data
    MessageProducer msgProd = sess.createProducer(dest);
    TextMessage message = sess.createTextMessage(data);
    message.setStringProperty("stringProperty", data);
    msgProd.send(message);
    // consume data
    TextMessage m = (TextMessage) msgCons.receive(RECEIVE_TIMEOUT);
    assertNotNull(m);
    assertEquals(data, m.getText());
    assertEquals(data, message.getStringProperty("stringProperty"));
}

21. MessageConsumerCloseTest#testConsumerCloseAndSessionCommit()

Project: qpid-java
File: MessageConsumerCloseTest.java
/**
     * JMS Session says "The content of a transaction's input and output units is simply those messages that have
     * been produced and consumed within the session's current transaction.".  Closing a consumer must not therefore
     * prevent previously received messages from being committed.
     */
public void testConsumerCloseAndSessionCommit() throws Exception {
    Connection connection = getConnection();
    connection.start();
    final Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    Destination destination = getTestQueue();
    MessageConsumer consumer1 = session.createConsumer(destination);
    sendMessage(session, destination, 2);
    Message message = consumer1.receive(RECEIVE_TIMEOUT);
    assertNotNull("First message is not received", message);
    assertEquals("First message unexpected has unexpected property", 0, message.getIntProperty(INDEX));
    consumer1.close();
    session.commit();
    MessageConsumer consumer2 = session.createConsumer(destination);
    message = consumer2.receive(RECEIVE_TIMEOUT);
    assertNotNull("Second message is not received", message);
    assertEquals("Second message unexpected has unexpected property", 1, message.getIntProperty(INDEX));
    message = consumer2.receive(100l);
    assertNull("Unexpected third message", message);
}

22. PropertyValueTest#sendReceiveMessageWithHeader()

Project: qpid-java
File: PropertyValueTest.java
private void sendReceiveMessageWithHeader(Connection connection, final String propName, final String propValue) throws Exception {
    connection.start();
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    Destination destination = session.createQueue(getTestQueueName());
    Message message = session.createMessage();
    message.setStringProperty(propName, propValue);
    MessageConsumer consumer = session.createConsumer(destination);
    MessageProducer producer = session.createProducer(destination);
    producer.setDisableMessageID(true);
    producer.setDisableMessageTimestamp(true);
    producer.send(message);
    session.commit();
    Message receivedMessage = consumer.receive(1000);
    assertNotNull("Message not received", receivedMessage);
    assertEquals("Message has unexpected property value", propValue, receivedMessage.getStringProperty(propName));
    session.commit();
}

23. JMSXUserIDTest#testJMSXUserIDDisabled()

Project: qpid-java
File: JMSXUserIDTest.java
public void testJMSXUserIDDisabled() throws Exception {
    String url = String.format("amqp://guest:guest@test/?brokerlist='tcp://localhost:%s'&populateJMSXUserID='false'", getDefaultBroker().getAmqpPort());
    Connection connection = getConnection(new AMQConnectionURL(url));
    Destination destination = getTestQueue();
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    MessageConsumer consumer = session.createConsumer(destination);
    MessageProducer producer = session.createProducer(destination);
    TextMessage message = session.createTextMessage("test");
    producer.send(message);
    String userId = message.getStringProperty("JMSXUserID");
    assertEquals("Unexpected user ID =[" + userId + "]", null, userId);
    session.commit();
    connection.start();
    Message receivedMessage = consumer.receive(RECEIVE_TIMEOUT);
    session.commit();
    assertNotNull("Expected receivedMessage not received", receivedMessage);
    String receivedUserId = receivedMessage.getStringProperty("JMSXUserID");
    assertEquals("Unexpected user ID " + receivedUserId, null, receivedUserId);
}

24. JMSXUserIDTest#testJMSXUserIDIsSetByDefault()

Project: qpid-java
File: JMSXUserIDTest.java
public void testJMSXUserIDIsSetByDefault() throws Exception {
    Connection connection = getConnection();
    Destination destination = getTestQueue();
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    MessageConsumer consumer = session.createConsumer(destination);
    MessageProducer producer = session.createProducer(destination);
    TextMessage message = session.createTextMessage("test");
    producer.send(message);
    assertEquals("Unexpected user ID", GUEST_USERNAME, message.getStringProperty("JMSXUserID"));
    session.commit();
    connection.start();
    Message receivedMessage = consumer.receive(RECEIVE_TIMEOUT);
    session.commit();
    assertNotNull("Expected receivedMessage not received", receivedMessage);
    assertEquals("Unexpected user ID", GUEST_USERNAME, receivedMessage.getStringProperty("JMSXUserID"));
}

25. JMSDestinationTest#testTopic()

Project: qpid-java
File: JMSDestinationTest.java
/**
     * Test a message sent to a topic comes back with JMSDestination topic
     *
     * @throws Exception
     */
public void testTopic() throws Exception {
    Topic topic = _session.createTopic(getTestQueueName() + "Topic");
    MessageConsumer consumer = _session.createConsumer(topic);
    sendMessage(_session, topic, 1);
    _connection.start();
    Message receivedMessage = consumer.receive(10000);
    assertNotNull("Message should not be null", receivedMessage);
    Destination receivedDestination = receivedMessage.getJMSDestination();
    assertNotNull("JMSDestination should not be null", receivedDestination);
    assertEquals("Incorrect Destination type", topic.getClass(), receivedDestination.getClass());
}

26. JMSDestinationTest#testQueue()

Project: qpid-java
File: JMSDestinationTest.java
/**
     * Test a message sent to a queue comes back with JMSDestination queue
     *
     * @throws Exception
     */
public void testQueue() throws Exception {
    Queue queue = _session.createQueue(getTestQueueName());
    MessageConsumer consumer = _session.createConsumer(queue);
    sendMessage(_session, queue, 1);
    _connection.start();
    Message receivedMessage = consumer.receive(10000);
    assertNotNull("Message should not be null", receivedMessage);
    Destination receivedDestination = receivedMessage.getJMSDestination();
    assertNotNull("JMSDestination should not be null", receivedDestination);
    assertEquals("Incorrect Destination type", queue.getClass(), receivedDestination.getClass());
}

27. ImmediateAndMandatoryPublishingTest#produceMessage()

Project: qpid-java
File: ImmediateAndMandatoryPublishingTest.java
private Message produceMessage(int acknowledgeMode, boolean pubSub, boolean mandatory, boolean immediate) throws JMSException {
    Session session = _connection.createSession(acknowledgeMode == Session.SESSION_TRANSACTED, acknowledgeMode);
    Destination destination = null;
    if (pubSub) {
        destination = session.createTopic(getTestQueueName());
    } else {
        destination = session.createQueue(getTestQueueName());
    }
    MessageProducer producer = ((AMQSession<?, ?>) session).createProducer(destination, mandatory, immediate);
    Message message = session.createMessage();
    producer.send(message);
    if (session.getTransacted()) {
        session.commit();
    }
    return message;
}

28. ImmediateAndMandatoryPublishingTest#consumerCreateAndClose()

Project: qpid-java
File: ImmediateAndMandatoryPublishingTest.java
private void consumerCreateAndClose(boolean pubSub, boolean durable) throws JMSException {
    Session session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = null;
    MessageConsumer consumer = null;
    if (pubSub) {
        destination = session.createTopic(getTestQueueName());
        if (durable) {
            consumer = session.createDurableSubscriber((Topic) destination, getTestName());
        } else {
            consumer = session.createConsumer(destination);
        }
    } else {
        destination = session.createQueue(getTestQueueName());
        consumer = session.createConsumer(destination);
    }
    consumer.close();
}

29. AddressBasedDestinationTest#testCustomizingSubscriptionQueue()

Project: qpid-java
File: AddressBasedDestinationTest.java
/**
     * Test Goals : Verifies that the subscription queue created is as specified under link properties.
     */
public void testCustomizingSubscriptionQueue() throws Exception {
    Session ssn = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    String xDeclareArgs = "x-declare: { exclusive: false, auto-delete: false," + "alternate-exchange: 'amq.fanout'," + "arguments: {'qpid.alert_size': 1000,'qpid.alert_count': 100}" + "}";
    String addr = "ADDR:amq.topic/test; {link: {name:my-queue, durable:true," + xDeclareArgs + "}}";
    Destination dest = ssn.createTopic(addr);
    MessageConsumer cons = ssn.createConsumer(dest);
    String verifyAddr = "ADDR:my-queue;{ node: {durable:true, " + xDeclareArgs + "}}";
    AMQDestination verifyDest = (AMQDestination) ssn.createQueue(verifyAddr);
    ((AMQSession) ssn).isQueueExist(verifyDest, true);
    // Verify that the producer does not delete the subscription queue.
    MessageProducer prod = ssn.createProducer(dest);
    prod.close();
    ((AMQSession) ssn).isQueueExist(verifyDest, true);
}

30. AddressBasedDestinationTest#testTopicRereceiveAfterRollback()

Project: qpid-java
File: AddressBasedDestinationTest.java
/**
    * Tests that a client using a session in {@link Session#SESSION_TRANSACTED} can correctly
    * rollback a session and re-receive the same message.
    */
public void testTopicRereceiveAfterRollback() throws Exception {
    final Session jmsSession = _connection.createSession(true, Session.SESSION_TRANSACTED);
    final Destination topic = jmsSession.createTopic("ADDR:amq.topic/topic1; {link:{name: queue1}}");
    final MessageProducer prod = jmsSession.createProducer(topic);
    final MessageConsumer consForTopic1 = jmsSession.createConsumer(topic);
    final Message sentMessage = jmsSession.createTextMessage("Hello");
    prod.send(sentMessage);
    jmsSession.commit();
    Message receivedMessage = consForTopic1.receive(1000);
    assertNotNull("message should be received by consumer", receivedMessage);
    jmsSession.rollback();
    receivedMessage = consForTopic1.receive(1000);
    assertNotNull("message should be re-received by consumer after rollback", receivedMessage);
    jmsSession.commit();
}

31. AddressBasedDestinationTest#testTopicRereceiveAfterRecover()

Project: qpid-java
File: AddressBasedDestinationTest.java
/**
     * Tests that a client using a session in {@link Session#CLIENT_ACKNOWLEDGE} can correctly
     * recover a session and re-receive the same message.
     */
public void testTopicRereceiveAfterRecover() throws Exception {
    final Session jmsSession = _connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    final Destination topic = jmsSession.createTopic("ADDR:amq.topic/topic1; {link:{name: queue1}}");
    final MessageProducer prod = jmsSession.createProducer(topic);
    final MessageConsumer consForTopic1 = jmsSession.createConsumer(topic);
    final Message sentMessage = jmsSession.createTextMessage("Hello");
    prod.send(sentMessage);
    Message receivedMessage = consForTopic1.receive(1000);
    assertNotNull("message should be received by consumer", receivedMessage);
    jmsSession.recover();
    receivedMessage = consForTopic1.receive(1000);
    assertNotNull("message should be re-received by consumer after recover", receivedMessage);
    receivedMessage.acknowledge();
}

32. AddressBasedDestinationTest#testXSubscribeOverrides()

Project: qpid-java
File: AddressBasedDestinationTest.java
public void testXSubscribeOverrides() throws Exception {
    Session ssn = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    String str = "ADDR:my_queue; {create:always, node: { type: queue }, link: {x-subscribes:{exclusive: true, arguments: {a:b,x:y}}}}";
    Destination dest = ssn.createTopic(str);
    MessageConsumer consumer1 = ssn.createConsumer(dest);
    try {
        MessageConsumer consumer2 = ssn.createConsumer(dest);
        fail("An exception should be thrown as 'my-queue' already have an exclusive subscriber");
    } catch (Exception e) {
    }
}

33. AddressBasedDestinationTest#testJMSTopicIsTreatedAsQueueIn0_10()

Project: qpid-java
File: AddressBasedDestinationTest.java
public void testJMSTopicIsTreatedAsQueueIn0_10() throws Exception {
    _connection = getConnection();
    _connection.start();
    final Session ssn = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    final Destination dest = ssn.createTopic("ADDR:my_queue; {create: always}");
    final MessageConsumer consumer1 = ssn.createConsumer(dest);
    final MessageConsumer consumer2 = ssn.createConsumer(dest);
    final MessageProducer prod = ssn.createProducer(dest);
    prod.send(ssn.createTextMessage("A"));
    Message m1 = consumer1.receive(1000);
    Message m2 = consumer2.receive(1000);
    if (m1 != null) {
        assertNull("Only one consumer should receive the message", m2);
    } else {
        assertNotNull("Only one consumer should receive the message", m2);
    }
}

34. QueueRestTest#setUp()

Project: qpid-java
File: QueueRestTest.java
public void setUp() throws Exception {
    super.setUp();
    _connection = getConnection();
    Session session = _connection.createSession(true, Session.SESSION_TRANSACTED);
    String queueName = getTestQueueName();
    Destination queue = session.createQueue(queueName);
    MessageConsumer consumer = session.createConsumer(queue);
    MessageProducer producer = session.createProducer(queue);
    for (int i = 0; i < MESSAGE_NUMBER; i++) {
        producer.send(session.createTextMessage("Test-" + i));
    }
    session.commit();
    _connection.start();
    Message m = consumer.receive(1000l);
    assertNotNull("Message is not received", m);
    session.commit();
}

35. PersistentStoreTest#confirmBrokerStillHasCommittedMessages()

Project: qpid-java
File: PersistentStoreTest.java
private void confirmBrokerStillHasCommittedMessages() throws Exception {
    Connection con = getConnection();
    Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
    con.start();
    Destination destination = session.createQueue(getTestQueueName());
    MessageConsumer consumer = session.createConsumer(destination);
    for (int i = 1; i <= NUM_MESSAGES; i++) {
        Message msg = consumer.receive(RECEIVE_TIMEOUT);
        assertNotNull("Message " + i + " not received", msg);
        assertEquals("Did not receive the expected message", i, msg.getIntProperty(INDEX));
    }
    Message msg = consumer.receive(100);
    if (msg != null) {
        fail("No more messages should be received, but received additional message with index: " + msg.getIntProperty(INDEX));
    }
}

36. ExternalACLTest#testClientCreateNamedQueueFailure()

Project: qpid-java
File: ExternalACLTest.java
public void testClientCreateNamedQueueFailure() throws NamingException, JMSException, QpidException, Exception {
    Connection conn = getConnection("test", "client", "guest");
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    conn.start();
    Destination dest = sess.createQueue("IllegalQueue");
    try {
        //Create a Named Queue as side effect
        sess.createConsumer(dest);
        fail("Test failed as Queue creation succeded.");
    } catch (JMSException e) {
        check403Exception(e.getLinkedException());
    }
}

37. ExternalACLTest#testClientConsumeFromNamedQueueFailure()

Project: qpid-java
File: ExternalACLTest.java
public void testClientConsumeFromNamedQueueFailure() throws NamingException, Exception {
    Connection conn = getConnection("test", "client", "guest");
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    conn.start();
    Destination dest = sess.createQueue("IllegalQueue");
    try {
        sess.createConsumer(dest);
        fail("Test failed as consumer was created.");
    } catch (JMSException e) {
        check403Exception(e.getLinkedException());
    }
}

38. ExternalACLTest#testClientCreateVirtualHostQueue()

Project: qpid-java
File: ExternalACLTest.java
public void testClientCreateVirtualHostQueue() throws NamingException, JMSException, QpidException, Exception {
    Connection conn = getConnection("test", "client", "guest");
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination dest = sess.createQueue(getTestQueueName());
    sess.createConsumer(dest);
    conn.close();
    try {
        conn = getConnection("test", "guest", "guest");
        sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        sess.createConsumer(dest);
        fail("Queue creation for user 'guest' is denied");
    } catch (JMSException e) {
        check403Exception(e.getLinkedException());
    }
}

39. QpidBrokerTestCase#assertProducingConsuming()

Project: qpid-java
File: QpidBrokerTestCase.java
/**
     * Tests that a connection is functional by producing and consuming a single message.
     * Will fail if failover interrupts either transaction.
     */
public void assertProducingConsuming(final Connection connection) throws Exception {
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    Destination destination = session.createQueue(getTestQueueName());
    MessageConsumer consumer = session.createConsumer(destination);
    sendMessage(session, destination, 1);
    session.commit();
    connection.start();
    Message m1 = consumer.receive(RECEIVE_TIMEOUT);
    assertNotNull("Message 1 is not received", m1);
    assertEquals("Unexpected first message received", 0, m1.getIntProperty(INDEX));
    session.commit();
    session.close();
}

40. ControllerJmsDelegate#createDestinationFromString()

Project: qpid-java
File: ControllerJmsDelegate.java
private Destination createDestinationFromString(final String clientQueueName) {
    Destination clientIntructionQueue;
    try {
        clientIntructionQueue = _commandSession.createQueue(clientQueueName);
    } catch (JMSException e) {
        throw new DistributedTestException("Unable to create Destination from " + clientQueueName);
    }
    return clientIntructionQueue;
}

41. AMQMessageDelegate_0_10#getReplyToString()

Project: qpid-java
File: AMQMessageDelegate_0_10.java
public String getReplyToString() {
    Destination replyTo = getJMSReplyTo();
    if (replyTo != null) {
        return ((AMQDestination) replyTo).toString();
    } else {
        return null;
    }
}

42. MapReceiver#main()

Project: qpid-java
File: MapReceiver.java
public static void main(String[] args) throws Exception {
    Connection connection = new AMQConnection("amqp://guest:guest@test/?brokerlist='tcp://localhost:5672'");
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination queue = new AMQAnyDestination("ADDR:message_queue; {create: always}");
    MessageConsumer consumer = session.createConsumer(queue);
    MapMessage m = (MapMessage) consumer.receive();
    System.out.println(m);
    connection.close();
}

43. BDBBackupTest#confirmBrokerHasMessages()

Project: qpid-java
File: BDBBackupTest.java
private void confirmBrokerHasMessages(final int startIndex, final int endIndex) throws Exception {
    Connection con = getConnection();
    Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
    con.start();
    Destination destination = session.createQueue(getTestQueueName());
    MessageConsumer consumer = session.createConsumer(destination);
    for (int i = startIndex; i < endIndex; i++) {
        Message msg = consumer.receive(RECEIVE_TIMEOUT);
        assertNotNull("Message " + i + " not received", msg);
        assertEquals("Did not receive the expected message", i, msg.getIntProperty(INDEX));
    }
    Message msg = consumer.receive(100);
    if (msg != null) {
        fail("No more messages should be received, but received additional message with index: " + msg.getIntProperty(INDEX));
    }
    con.close();
}

44. BDBBackupTest#sendNumberedMessages()

Project: qpid-java
File: BDBBackupTest.java
private void sendNumberedMessages(final int startIndex, final int endIndex) throws JMSException, Exception {
    Connection con = getConnection();
    Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = session.createQueue(getTestQueueName());
    // Create queue by consumer side-effect
    session.createConsumer(destination).close();
    final int numOfMessages = endIndex - startIndex;
    final int batchSize = 0;
    sendMessage(session, destination, numOfMessages, startIndex, batchSize);
    con.close();
}

45. JmsProxyHandler#createOrReturnQueueOrTopic()

Project: openwebbeans
File: JmsProxyHandler.java
private Destination createOrReturnQueueOrTopic() {
    JMSModel jmsModel = this.jmsComponent.getJmsModel();
    String jndiName = jmsModel.isJndiNameDefined() ? jmsModel.getJndiName() : jmsModel.getMappedName();
    if (dests.get(jndiName) != null) {
        return dests.get(jndiName);
    }
    Destination res = (Destination) JmsUtil.getInstanceFromJndi(this.jmsComponent.getJmsModel(), this.injectionClazz);
    dests.put(jndiName, res);
    return res;
}

46. SimpleJmsTest#testProxy()

Project: openejb
File: SimpleJmsTest.java
public void testProxy() throws Exception {
    // create reciever object
    TestObject testObject = new TestObject("foo");
    MdbInvoker mdbInvoker = new MdbInvoker(connectionFactory, testObject);
    // Create a Session
    Connection connection = connectionFactory.createConnection();
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    // Create the request Queue
    Destination requestQueue = session.createQueue(REQUEST_QUEUE_NAME);
    MessageConsumer consumer = session.createConsumer(requestQueue);
    consumer.setMessageListener(mdbInvoker);
    // create in invoker
    TestInterface testInterface = MdbProxy.newProxyInstance(TestInterface.class, connectionFactory, REQUEST_QUEUE_NAME);
    assertEquals("foobar", testInterface.echo("bar"));
    assertEquals("foobar", testInterface.echo("bar"));
    assertEquals("foobar", testInterface.echo("bar"));
    assertEquals("foobar", testInterface.echo("bar"));
    assertEquals("foobar", testInterface.echo("bar"));
}

47. JmsProxyTest#testProxy()

Project: openejb
File: JmsProxyTest.java
public void testProxy() throws Exception {
    // create reciever object
    JmsProxyTest.TestObject testObject = new JmsProxyTest.TestObject("foo");
    MdbInvoker mdbInvoker = new MdbInvoker(connectionFactory, testObject);
    // Create a Session
    Connection connection = connectionFactory.createConnection();
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    // Create the request Queue
    Destination requestQueue = session.createQueue(REQUEST_QUEUE_NAME);
    MessageConsumer consumer = session.createConsumer(requestQueue);
    consumer.setMessageListener(mdbInvoker);
    // create in invoker
    JmsProxyTest.TestInterface testInterface = MdbProxy.newProxyInstance(JmsProxyTest.TestInterface.class, connectionFactory, REQUEST_QUEUE_NAME);
    assertEquals("foobar", testInterface.echo("bar"));
    assertEquals("foobar", testInterface.echo("bar"));
    assertEquals("foobar", testInterface.echo("bar"));
    assertEquals("foobar", testInterface.echo("bar"));
    assertEquals("foobar", testInterface.echo("bar"));
}

48. ProxyConnectionFactory#getMessage()

Project: lemon
File: ProxyConnectionFactory.java
public Message getMessage(MessageContext messageContext, ProxyMessageConsumer proxyMessageConsumer) throws JMSException {
    String destinationName = proxyMessageConsumer.getDestination().toString();
    Destination destination = destinationMap.get(destinationName);
    if (destination instanceof Topic) {
        return messageHandler.consumeMessageFromTopic(messageContext, destinationName, proxyMessageConsumer.getId());
    } else {
        return messageHandler.consumeMessageFromQueue(messageContext, destinationName);
    }
}

49. IgniteJmsStreamerTest#testTransactedSessionNoBatching()

Project: ignite
File: IgniteJmsStreamerTest.java
public void testTransactedSessionNoBatching() throws Exception {
    Destination destination = new ActiveMQQueue(QUEUE_NAME);
    // produce multiple messages into the queue
    produceStringMessages(destination, false);
    try (IgniteDataStreamer<String, String> dataStreamer = grid().dataStreamer(null)) {
        JmsStreamer<TextMessage, String, String> jmsStreamer = newJmsStreamer(TextMessage.class, dataStreamer);
        jmsStreamer.setTransacted(true);
        jmsStreamer.setDestination(destination);
        // subscribe to cache PUT events and return a countdown latch starting at CACHE_ENTRY_COUNT
        CountDownLatch latch = subscribeToPutEvents(CACHE_ENTRY_COUNT);
        jmsStreamer.start();
        // all cache PUT events received in 10 seconds
        latch.await(10, TimeUnit.SECONDS);
        assertAllCacheEntriesLoaded();
        jmsStreamer.stop();
    }
}

50. IgniteJmsStreamerTest#testGenerateNoEntries()

Project: ignite
File: IgniteJmsStreamerTest.java
public void testGenerateNoEntries() throws Exception {
    Destination destination = new ActiveMQQueue(QUEUE_NAME);
    // produce multiple messages into the queue
    produceStringMessages(destination, false);
    try (IgniteDataStreamer<String, String> dataStreamer = grid().dataStreamer(null)) {
        JmsStreamer<TextMessage, String, String> jmsStreamer = newJmsStreamer(TextMessage.class, dataStreamer);
        // override the transformer with one that generates no cache entries
        jmsStreamer.setTransformer(TestTransformers.generateNoEntries());
        jmsStreamer.setDestination(destination);
        // subscribe to cache PUT events and return a countdown latch starting at CACHE_ENTRY_COUNT
        CountDownLatch latch = subscribeToPutEvents(1);
        jmsStreamer.start();
        // no cache PUT events were received in 3 seconds, i.e. CountDownLatch does not fire
        assertFalse(latch.await(3, TimeUnit.SECONDS));
        jmsStreamer.stop();
    }
}

51. IgniteJmsStreamerTest#testInsertMultipleCacheEntriesFromOneMessage()

Project: ignite
File: IgniteJmsStreamerTest.java
public void testInsertMultipleCacheEntriesFromOneMessage() throws Exception {
    Destination destination = new ActiveMQQueue(QUEUE_NAME);
    // produce A SINGLE MESSAGE, containing all data, into the queue
    produceStringMessages(destination, true);
    try (IgniteDataStreamer<String, String> dataStreamer = grid().dataStreamer(null)) {
        JmsStreamer<TextMessage, String, String> jmsStreamer = newJmsStreamer(TextMessage.class, dataStreamer);
        jmsStreamer.setDestination(destination);
        // subscribe to cache PUT events and return a countdown latch starting at CACHE_ENTRY_COUNT
        CountDownLatch latch = subscribeToPutEvents(CACHE_ENTRY_COUNT);
        jmsStreamer.start();
        // all cache PUT events received in 10 seconds
        latch.await(10, TimeUnit.SECONDS);
        assertAllCacheEntriesLoaded();
        jmsStreamer.stop();
    }
}

52. IgniteJmsStreamerTest#testQueueFromExplicitDestination()

Project: ignite
File: IgniteJmsStreamerTest.java
public void testQueueFromExplicitDestination() throws Exception {
    Destination destination = new ActiveMQQueue(QUEUE_NAME);
    // produce messages into the queue
    produceObjectMessages(destination, false);
    try (IgniteDataStreamer<String, String> dataStreamer = grid().dataStreamer(null)) {
        JmsStreamer<ObjectMessage, String, String> jmsStreamer = newJmsStreamer(ObjectMessage.class, dataStreamer);
        jmsStreamer.setDestination(destination);
        // subscribe to cache PUT events and return a countdown latch starting at CACHE_ENTRY_COUNT
        CountDownLatch latch = subscribeToPutEvents(CACHE_ENTRY_COUNT);
        // start the streamer
        jmsStreamer.start();
        // all cache PUT events received in 10 seconds
        latch.await(10, TimeUnit.SECONDS);
        assertAllCacheEntriesLoaded();
        jmsStreamer.stop();
    }
}

53. IgniteJmsStreamerTest#testQueueFromName()

Project: ignite
File: IgniteJmsStreamerTest.java
public void testQueueFromName() throws Exception {
    Destination destination = new ActiveMQQueue(QUEUE_NAME);
    // produce messages into the queue
    produceObjectMessages(destination, false);
    try (IgniteDataStreamer<String, String> dataStreamer = grid().dataStreamer(null)) {
        JmsStreamer<ObjectMessage, String, String> jmsStreamer = newJmsStreamer(ObjectMessage.class, dataStreamer);
        jmsStreamer.setDestinationType(Queue.class);
        jmsStreamer.setDestinationName(QUEUE_NAME);
        // subscribe to cache PUT events and return a countdown latch starting at CACHE_ENTRY_COUNT
        CountDownLatch latch = subscribeToPutEvents(CACHE_ENTRY_COUNT);
        jmsStreamer.start();
        // all cache PUT events received in 10 seconds
        latch.await(10, TimeUnit.SECONDS);
        assertAllCacheEntriesLoaded();
        jmsStreamer.stop();
    }
}

54. FalconPostProcessingTest#consumer()

Project: falcon
File: FalconPostProcessingTest.java
private void consumer(String brokerUrl, String topic, boolean checkUserMessage) throws JMSException {
    ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerUrl);
    Connection connection = connectionFactory.createConnection();
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = session.createTopic(topic);
    MessageConsumer consumer = session.createConsumer(destination);
    latch.countDown();
    // Verify user message
    if (checkUserMessage) {
        verifyMesssage(consumer);
    }
    connection.close();
}

55. ProcessProducerTest#consumer()

Project: falcon
File: ProcessProducerTest.java
private void consumer() throws JMSException {
    ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(BROKER_URL);
    Connection connection = connectionFactory.createConnection();
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = session.createTopic(getTopicName());
    MessageConsumer consumer = session.createConsumer(destination);
    latch.countDown();
    for (int index = 0; index < outputFeedNames.length; ++index) {
        MapMessage m = (MapMessage) consumer.receive();
        System.out.println("Consumed: " + m.toString());
        assertMessage(m);
        Assert.assertEquals(m.getString(WorkflowExecutionArgs.OUTPUT_FEED_NAMES.getName()), outputFeedNames[index]);
        Assert.assertEquals(m.getString(WorkflowExecutionArgs.OUTPUT_FEED_PATHS.getName()), outputFeedPaths[index]);
    }
    connection.close();
}

56. JMSMessageProducerTest#consumer()

Project: falcon
File: JMSMessageProducerTest.java
private void consumer(int size, String topicsToListen, CountDownLatch latch) throws Exception {
    ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(BROKER_URL);
    Connection connection = connectionFactory.createConnection();
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = session.createTopic(topicsToListen);
    MessageConsumer consumer = session.createConsumer(destination);
    latch.countDown();
    mapMessages = new ArrayList<MapMessage>();
    for (int i = 0; i < size; i++) {
        MapMessage m = (MapMessage) consumer.receive();
        mapMessages.add(m);
        System.out.println("Consumed: " + m.toString());
    }
    connection.close();
}

57. FeedProducerTest#consumer()

Project: falcon
File: FeedProducerTest.java
private void consumer() throws JMSException {
    ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(BROKER_URL);
    Connection connection = connectionFactory.createConnection();
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = session.createTopic(TOPIC_NAME);
    MessageConsumer consumer = session.createConsumer(destination);
    latch.countDown();
    verifyMesssage(consumer);
    connection.close();
}

58. OrderClient#sendOrder()

Project: camelinaction
File: OrderClient.java
public void sendOrder(int customerId, Date date, String... itemIds) throws Exception {
    // format the JMS message from the input parameters
    String d = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(date);
    String body = customerId + "," + d;
    for (String id : itemIds) {
        body += "," + id;
    }
    // use JMS code to send the message (a bit ugly code but it works)
    Connection con = fac.createConnection();
    con.start();
    Session ses = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination dest = ses.createQueue("order");
    MessageProducer prod = ses.createProducer(dest);
    prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
    Message msg = ses.createTextMessage(body);
    prod.send(msg);
    prod.close();
    ses.close();
    con.close();
}

59. DefaultDestinationCreationStrategy#createDestination()

Project: camel
File: DefaultDestinationCreationStrategy.java
@Override
public Destination createDestination(final Session session, String name, final boolean topic) throws JMSException {
    Destination destination;
    if (topic) {
        if (name.startsWith(TOPIC_PREFIX)) {
            name = name.substring(TOPIC_PREFIX.length());
        }
        destination = session.createTopic(name);
    } else {
        if (name.startsWith(QUEUE_PREFIX)) {
            name = name.substring(QUEUE_PREFIX.length());
        }
        destination = session.createQueue(name);
    }
    return destination;
}

60. JmsProducerWithJMSHeaderTest#testInOnlyJMSDestination()

Project: camel
File: JmsProducerWithJMSHeaderTest.java
@Test
public void testInOnlyJMSDestination() throws Exception {
    Destination queue = new ActiveMQQueue("foo");
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    mock.message(0).header("JMSDestination").isNotNull();
    template.sendBodyAndHeader("activemq:queue:bar", "Hello World", JmsConstants.JMS_DESTINATION, queue);
    assertMockEndpointsSatisfied();
    assertEquals("queue://foo", mock.getReceivedExchanges().get(0).getIn().getHeader("JMSDestination", Destination.class).toString());
}

61. JmsCustomJMSReplyToIssueTest#testCustomJMSReplyTo()

Project: camel
File: JmsCustomJMSReplyToIssueTest.java
@Test
public void testCustomJMSReplyTo() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Bye World");
    // start a inOnly route
    template.sendBody("direct:start", "Hello World");
    // now consume using something that is not Camel
    Thread.sleep(1000);
    JmsTemplate jms = new JmsTemplate(amq.getConfiguration().getConnectionFactory());
    TextMessage msg = (TextMessage) jms.receive("in");
    assertEquals("Hello World", msg.getText());
    // there should be a JMSReplyTo so we know where to send the reply
    Destination replyTo = msg.getJMSReplyTo();
    assertEquals("queue://myReplyQueue", replyTo.toString());
    // send reply
    template.sendBody("activemq:" + replyTo.toString(), "Bye World");
    assertMockEndpointsSatisfied();
}

62. JmsAnotherCustomJMSReplyToTest#testCustomJMSReplyToInOnly()

Project: camel
File: JmsAnotherCustomJMSReplyToTest.java
@Test
public void testCustomJMSReplyToInOnly() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("My name is Arnio");
    // start a inOnly route
    template.sendBody("activemq:queue:hello", "Hello, I'm here");
    // now consume using something that is not Camel
    Thread.sleep(1000);
    JmsTemplate jms = new JmsTemplate(amq.getConfiguration().getConnectionFactory());
    TextMessage msg = (TextMessage) jms.receive("nameRequestor");
    assertEquals("What's your name", msg.getText());
    // there should be a JMSReplyTo so we know where to send the reply
    Destination replyTo = msg.getJMSReplyTo();
    assertEquals("queue://nameReplyQueue", replyTo.toString());
    // send reply
    template.sendBody("activemq:" + replyTo.toString(), "My name is Arnio");
    Thread.sleep(2000);
    assertMockEndpointsSatisfied();
}

63. ActiveJmsSender#sendToQueue()

Project: c2mon
File: ActiveJmsSender.java
@Override
public void sendToQueue(final String text, final String jmsQueueName) {
    if (text == null) {
        throw new NullPointerException("Attempting to send a null text message.");
    }
    Destination queue = new ActiveMQQueue(jmsQueueName);
    jmsTemplate.send(queue, new MessageCreator() {

        @Override
        public Message createMessage(Session session) throws JMSException {
            return session.createTextMessage(text);
        }
    });
}

64. ActiveJmsSender#sendToTopic()

Project: c2mon
File: ActiveJmsSender.java
@Override
public void sendToTopic(final String text, final String jmsTopicName) {
    if (text == null) {
        throw new NullPointerException("Attempting to send a null text message.");
    }
    Destination topic = new ActiveMQTopic(jmsTopicName);
    jmsTemplate.send(topic, new MessageCreator() {

        @Override
        public Message createMessage(Session session) throws JMSException {
            return session.createTextMessage(text);
        }
    });
}

65. JMSObjectInputOperatorTest#produceMsg()

Project: apex-malhar
File: JMSObjectInputOperatorTest.java
private void produceMsg() throws Exception {
    // Create a ConnectionFactory
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost");
    // Create a Connection
    testMeta.connection = connectionFactory.createConnection();
    testMeta.connection.start();
    // Create a Session
    testMeta.session = testMeta.connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    // Create the destination (Topic or Queue)
    Destination destination = testMeta.session.createQueue("TEST.FOO");
    // Create a MessageProducer from the Session to the Topic or Queue
    testMeta.producer = testMeta.session.createProducer(destination);
    testMeta.producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
}

66. MessageHeaderTest#testForeignJMSDestination()

Project: activemq-artemis
File: MessageHeaderTest.java
@Test
public void testForeignJMSDestination() throws JMSException {
    Message message = queueProducerSession.createMessage();
    Destination foreignDestination = new ForeignDestination();
    message.setJMSDestination(foreignDestination);
    ProxyAssertSupport.assertSame(foreignDestination, message.getJMSDestination());
    queueProducer.send(message);
    ProxyAssertSupport.assertSame(queue1, message.getJMSDestination());
    Message receivedMessage = queueConsumer.receive(2000);
    MessageHeaderTestBase.ensureEquivalent(receivedMessage, (ActiveMQMessage) message);
}

67. ProtonTest#testReplyToNonJMS()

Project: activemq-artemis
File: ProtonTest.java
@Test
public void testReplyToNonJMS() throws Throwable {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryQueue queue = session.createTemporaryQueue();
    System.out.println("queue:" + queue.getQueueName());
    MessageProducer p = session.createProducer(queue);
    TextMessage message = session.createTextMessage();
    message.setText("Message temporary");
    message.setJMSReplyTo(createQueue("someaddress"));
    p.send(message);
    MessageConsumer cons = session.createConsumer(queue);
    connection.start();
    message = (TextMessage) cons.receive(5000);
    Destination jmsReplyTo = message.getJMSReplyTo();
    Assert.assertNotNull(jmsReplyTo);
    Assert.assertNotNull(message);
}

68. ProtonTest#testReplyTo()

Project: activemq-artemis
File: ProtonTest.java
@Test
public void testReplyTo() throws Throwable {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryQueue queue = session.createTemporaryQueue();
    System.out.println("queue:" + queue.getQueueName());
    MessageProducer p = session.createProducer(queue);
    TextMessage message = session.createTextMessage();
    message.setText("Message temporary");
    message.setJMSReplyTo(createQueue(address));
    p.send(message);
    MessageConsumer cons = session.createConsumer(queue);
    connection.start();
    message = (TextMessage) cons.receive(5000);
    Destination jmsReplyTo = message.getJMSReplyTo();
    Assert.assertNotNull(jmsReplyTo);
    Assert.assertNotNull(message);
}

69. SimpleJNDIClientTest#testTopic()

Project: activemq-artemis
File: SimpleJNDIClientTest.java
@Test
public void testTopic() throws NamingException, JMSException {
    Hashtable<String, String> props = new Hashtable<>();
    props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
    props.put("topic.myTopic", "myTopic");
    props.put("topic.topics/myTopic", "myTopic");
    Context ctx = new InitialContext(props);
    Destination destination = (Destination) ctx.lookup("myTopic");
    Assert.assertTrue(destination instanceof Topic);
    destination = (Destination) ctx.lookup("topics/myTopic");
    Assert.assertTrue(destination instanceof Topic);
}

70. SimpleJNDIClientTest#testQueue()

Project: activemq-artemis
File: SimpleJNDIClientTest.java
@Test
public void testQueue() throws NamingException, JMSException {
    Hashtable<String, String> props = new Hashtable<>();
    props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
    props.put("queue.myQueue", "myQueue");
    props.put("queue.queues/myQueue", "myQueue");
    Context ctx = new InitialContext(props);
    Destination destination = (Destination) ctx.lookup("myQueue");
    Assert.assertTrue(destination instanceof Queue);
    destination = (Destination) ctx.lookup("queues/myQueue");
    Assert.assertTrue(destination instanceof Queue);
}

71. StoreConfigTest#checkDestination()

Project: activemq-artemis
File: StoreConfigTest.java
private void checkDestination(String name) throws Exception {
    ConnectionFactory cf = (ConnectionFactory) namingContext.lookup("/someCF");
    Connection conn = cf.createConnection();
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination dest = (Destination) namingContext.lookup(name);
    conn.start();
    MessageConsumer cons = sess.createConsumer(dest);
    MessageProducer prod = sess.createProducer(dest);
    prod.send(sess.createMessage());
    assertNotNull(cons.receiveNoWait());
    conn.close();
}

72. TwoBrokerVirtualDestDinamicallyIncludedDestTest#testVirtualDestinationsDinamicallyIncludedBehavior2()

Project: activemq-artemis
File: TwoBrokerVirtualDestDinamicallyIncludedDestTest.java
/**
    * BrokerA -> BrokerB && BrokerB -> BrokerA
    */
public void testVirtualDestinationsDinamicallyIncludedBehavior2() throws Exception {
    startAllBrokers();
    // Setup destination
    Destination dest = createDestination("global.test", true);
    // Setup consumers
    //MessageConsumer clientB1 = createConsumer("BrokerB", dest);
    MessageConsumer clientB2 = createConsumer("BrokerB", createDestination("Consumer.foo-bar.global.test", false));
    Thread.sleep(2 * 1000);
    // Send messages
    sendMessages("BrokerA", dest, MESSAGE_COUNT);
    // Get message count
    MessageIdList msgsB2 = getConsumerMessages("BrokerB", clientB2);
    msgsB2.waitForMessagesToArrive(MESSAGE_COUNT);
    assertEquals(MESSAGE_COUNT, msgsB2.getMessageCount());
}

73. TwoBrokerMulticastQueueTest#doMultipleConsumersConnectTest()

Project: activemq-artemis
File: TwoBrokerMulticastQueueTest.java
private void doMultipleConsumersConnectTest() throws Exception {
    Destination dest = new ActiveMQQueue("TEST.FOO");
    ConnectionFactory sendFactory = createConnectionFactory(sendUri);
    Connection conn = createConnection(sendFactory);
    sendMessages(conn, dest, MESSAGE_COUNT);
    Thread.sleep(500);
    ConnectionFactory recvFactory = createConnectionFactory(recvUri);
    assertEquals(MESSAGE_COUNT, receiveMessages(createConnection(recvFactory), dest, 0));
    for (int i = 0; i < (CONSUMER_COUNT - 1); i++) {
        assertEquals(0, receiveMessages(createConnection(recvFactory), dest, 200));
    }
}

74. TwoBrokerMulticastQueueTest#doSendReceiveTest()

Project: activemq-artemis
File: TwoBrokerMulticastQueueTest.java
private void doSendReceiveTest() throws Exception {
    Destination dest = new ActiveMQQueue("TEST.FOO");
    ConnectionFactory sendFactory = createConnectionFactory(sendUri);
    Connection conn = createConnection(sendFactory);
    sendMessages(conn, dest, MESSAGE_COUNT);
    Thread.sleep(500);
    ConnectionFactory recvFactory = createConnectionFactory(recvUri);
    assertEquals(MESSAGE_COUNT, receiveMessages(createConnection(recvFactory), dest, 0));
}

75. TwoBrokerMessageNotSentToRemoteWhenNoConsumerTest#testRemoteBrokerHasNoConsumer()

Project: activemq-artemis
File: TwoBrokerMessageNotSentToRemoteWhenNoConsumerTest.java
/**
    * BrokerA -> BrokerB
    */
public void testRemoteBrokerHasNoConsumer() throws Exception {
    // Setup broker networks
    bridgeBrokers("BrokerA", "BrokerB");
    startAllBrokers();
    // Setup destination
    Destination dest = createDestination("TEST.FOO", true);
    // Setup consumers
    MessageConsumer clientA = createConsumer("BrokerA", dest);
    // Send messages
    sendMessages("BrokerA", dest, MESSAGE_COUNT);
    // Get message count
    MessageIdList msgsA = getConsumerMessages("BrokerA", clientA);
    msgsA.waitForMessagesToArrive(MESSAGE_COUNT);
    assertEquals(MESSAGE_COUNT, msgsA.getMessageCount());
}

76. ThreeBrokerQueueNetworkTest#testAllConnectedWithSpare()

Project: activemq-artemis
File: ThreeBrokerQueueNetworkTest.java
public void testAllConnectedWithSpare() throws Exception {
    bridgeAllBrokers("default", 3, false);
    startAllBrokers();
    waitForBridgeFormation();
    // Setup destination
    Destination dest = createDestination("TEST.FOO", false);
    // Setup consumers
    int messageCount = 2000;
    CountDownLatch messagesReceived = new CountDownLatch(messageCount);
    MessageConsumer clientA = createConsumer("BrokerA", dest, messagesReceived);
    // ensure advisory percolation.
    Thread.sleep(2000);
    // Send messages
    sendMessages("BrokerB", dest, messageCount);
    assertTrue("messaged received within time limit", messagesReceived.await(30, TimeUnit.SECONDS));
    // Get message count
    MessageIdList msgsA = getConsumerMessages("BrokerA", clientA);
    assertEquals(messageCount, msgsA.getMessageCount());
}

77. ThreeBrokerQueueNetworkTest#testAllConnectedUsingMulticastProducerConsumerOnA()

Project: activemq-artemis
File: ThreeBrokerQueueNetworkTest.java
public void testAllConnectedUsingMulticastProducerConsumerOnA() throws Exception {
    bridgeAllBrokers("default", 3, false);
    startAllBrokers();
    waitForBridgeFormation();
    // Setup destination
    Destination dest = createDestination("TEST.FOO", false);
    // Setup consumers
    int messageCount = 2000;
    CountDownLatch messagesReceived = new CountDownLatch(messageCount);
    MessageConsumer clientA = createConsumer("BrokerA", dest, messagesReceived);
    // Let's try to wait for advisory percolation.
    Thread.sleep(1000);
    // Send messages
    sendMessages("BrokerA", dest, messageCount);
    assertTrue(messagesReceived.await(30, TimeUnit.SECONDS));
    // Get message count
    MessageIdList msgsA = getConsumerMessages("BrokerA", clientA);
    assertEquals(messageCount, msgsA.getMessageCount());
}

78. ThreeBrokerQueueNetworkTest#testABandCBbrokerNetwork()

Project: activemq-artemis
File: ThreeBrokerQueueNetworkTest.java
/**
    * BrokerA -> BrokerB <- BrokerC
    */
public void testABandCBbrokerNetwork() throws Exception {
    // Setup broker networks
    bridgeBrokers("BrokerA", "BrokerB");
    bridgeBrokers("BrokerC", "BrokerB");
    startAllBrokers();
    waitForBridgeFormation();
    // Setup destination
    Destination dest = createDestination("TEST.FOO", false);
    // Setup consumers
    MessageConsumer clientB = createConsumer("BrokerB", dest);
    // Send messages
    sendMessages("BrokerA", dest, MESSAGE_COUNT);
    sendMessages("BrokerC", dest, MESSAGE_COUNT);
    // Get message count
    MessageIdList msgsB = getConsumerMessages("BrokerB", clientB);
    msgsB.waitForMessagesToArrive(MESSAGE_COUNT * 2);
    assertEquals(MESSAGE_COUNT * 2, msgsB.getMessageCount());
}

79. ThreeBrokerQueueNetworkTest#testABandBCbrokerNetwork()

Project: activemq-artemis
File: ThreeBrokerQueueNetworkTest.java
/**
    * BrokerA -> BrokerB -> BrokerC
    */
public void testABandBCbrokerNetwork() throws Exception {
    // Setup broker networks
    bridgeBrokers("BrokerA", "BrokerB");
    bridgeBrokers("BrokerB", "BrokerC");
    startAllBrokers();
    waitForBridgeFormation();
    // Setup destination
    Destination dest = createDestination("TEST.FOO", false);
    // Setup consumers
    MessageConsumer clientC = createConsumer("BrokerC", dest);
    // Send messages
    sendMessages("BrokerA", dest, MESSAGE_COUNT);
    // Let's try to wait for any messages. Should be none.
    Thread.sleep(1000);
    // Get message count
    MessageIdList msgsC = getConsumerMessages("BrokerC", clientC);
    assertEquals(0, msgsC.getMessageCount());
}

80. RequestReplyToTopicViaThreeNetworkHopsTest#testOneDest()

Project: activemq-artemis
File: RequestReplyToTopicViaThreeNetworkHopsTest.java
/**
    * Test one destination between the given "producer broker" and "consumer broker" specified.
    */
public void testOneDest(Connection conn, Session sess, Destination cons_dest, int num_msg) throws Exception {
    Destination prod_dest;
    MessageProducer msg_prod;
    //
    // Create the Producer to the echo request Queue
    //
    LOG.trace("Creating echo queue and producer");
    prod_dest = sess.createQueue("echo");
    msg_prod = sess.createProducer(prod_dest);
    //
    // Pass messages around.
    //
    testMessages(sess, msg_prod, cons_dest, num_msg);
    msg_prod.close();
}

81. PublishOnTopicConsumedMessageTest#setUp()

Project: activemq-artemis
File: PublishOnTopicConsumedMessageTest.java
@Override
protected void setUp() throws Exception {
    super.setUp();
    Destination replyDestination = null;
    if (topic) {
        replyDestination = receiveSession.createTopic("REPLY." + getSubject());
    } else {
        replyDestination = receiveSession.createQueue("REPLY." + getSubject());
    }
    replyProducer = receiveSession.createProducer(replyDestination);
    LOG.info("Created replyProducer: " + replyProducer);
}

82. MulticastDiscoveryOnFaultyNetworkTest#testSendOnAFaultyTransport()

Project: activemq-artemis
File: MulticastDiscoveryOnFaultyNetworkTest.java
public void testSendOnAFaultyTransport() throws Exception {
    bridgeBrokers(SPOKE, HUB);
    startAllBrokers();
    // Setup destination
    Destination dest = createDestination("TEST.FOO", false);
    // Setup consumers
    MessageConsumer client = createConsumer(HUB, dest);
    // allow subscription information to flow back to Spoke
    sleep(600);
    // Send messages
    sendMessages(SPOKE, dest, MESSAGE_COUNT);
    MessageIdList msgs = getConsumerMessages(HUB, client);
    msgs.setMaximumDuration(200000L);
    msgs.waitForMessagesToArrive(MESSAGE_COUNT);
    assertTrue("At least message " + MESSAGE_COUNT + " must be received, duplicates are expected, count=" + msgs.getMessageCount(), MESSAGE_COUNT <= msgs.getMessageCount());
}

83. CompositeConsumeTest#testSendReceive()

Project: activemq-artemis
File: CompositeConsumeTest.java
@Override
public void testSendReceive() throws Exception {
    messages.clear();
    Destination[] destinations = getDestinations();
    int destIdx = 0;
    for (int i = 0; i < data.length; i++) {
        Message message = session.createTextMessage(data[i]);
        if (verbose) {
            LOG.info("About to send a message: " + message + " with text: " + data[i]);
        }
        producer.send(destinations[destIdx], message);
        if (++destIdx >= destinations.length) {
            destIdx = 0;
        }
    }
    assertMessagesAreReceived();
}

84. ChangeSessionDeliveryModeTest#testDoChangeSessionDeliveryMode()

Project: activemq-artemis
File: ChangeSessionDeliveryModeTest.java
/**
    * test following condition- which are defined by JMS Spec 1.1:
    * MessageConsumers cannot use a MessageListener and receive() from the same
    * session
    *
    * @throws Exception
    */
public void testDoChangeSessionDeliveryMode() throws Exception {
    Destination destination = createDestination("foo.bar");
    Connection connection = createConnection();
    connection.start();
    Session consumerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer1 = consumerSession.createConsumer(destination);
    consumer1.setMessageListener(this);
    MessageConsumer consumer2 = consumerSession.createConsumer(destination);
    try {
        consumer2.receive(10);
        fail("Did not receive expected exception.");
    } catch (JMSException e) {
        assertTrue(e instanceof IllegalStateException);
    }
}

85. ChangeSentMessageTest#testDoChangeSentMessage()

Project: activemq-artemis
File: ChangeSentMessageTest.java
/**
    * test Object messages can be changed after sending with no side-affects
    *
    * @throws Exception
    */
@SuppressWarnings("rawtypes")
public void testDoChangeSentMessage() throws Exception {
    Destination destination = createDestination("test-" + ChangeSentMessageTest.class.getName());
    Connection connection = createConnection();
    connection.start();
    Session consumerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = consumerSession.createConsumer(destination);
    Session publisherSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = publisherSession.createProducer(destination);
    HashMap<String, Integer> map = new HashMap<>();
    ObjectMessage message = publisherSession.createObjectMessage();
    for (int i = 0; i < COUNT; i++) {
        map.put(VALUE_NAME, Integer.valueOf(i));
        message.setObject(map);
        producer.send(message);
        assertTrue(message.getObject() == map);
    }
    for (int i = 0; i < COUNT; i++) {
        ObjectMessage msg = (ObjectMessage) consumer.receive();
        HashMap receivedMap = (HashMap) msg.getObject();
        Integer intValue = (Integer) receivedMap.get(VALUE_NAME);
        assertTrue(intValue.intValue() == i);
    }
}

86. BrowseOverNetworkTest#testConsumerInfo()

Project: activemq-artemis
File: BrowseOverNetworkTest.java
public void testConsumerInfo() throws Exception {
    createBroker(new ClassPathResource("org/apache/activemq/usecases/browse-broker1.xml"));
    createBroker(new ClassPathResource("org/apache/activemq/usecases/browse-broker2.xml"));
    startAllBrokers();
    brokers.get("broker1").broker.waitUntilStarted();
    Destination dest = createDestination("QUEUE.A,QUEUE.B", false);
    int broker1 = browseMessages("broker1", dest);
    assertEquals("Browsed a message on an empty queue", 0, broker1);
    Thread.sleep(1000);
    int broker2 = browseMessages("broker2", dest);
    assertEquals("Browsed a message on an empty queue", 0, broker2);
}

87. BrokerQueueNetworkWithDisconnectTest#testSendOnAReceiveOnBWithTransportDisconnect()

Project: activemq-artemis
File: BrokerQueueNetworkWithDisconnectTest.java
public void testSendOnAReceiveOnBWithTransportDisconnect() throws Exception {
    bridgeBrokers(SPOKE, HUB);
    startAllBrokers();
    // Setup destination
    Destination dest = createDestination("TEST.FOO", false);
    // Setup consumers
    MessageConsumer client = createConsumer(HUB, dest);
    // allow subscription information to flow back to Spoke
    sleep(600);
    // Send messages
    sendMessages(SPOKE, dest, MESSAGE_COUNT);
    MessageIdList msgs = getConsumerMessages(HUB, client);
    msgs.waitForMessagesToArrive(MESSAGE_COUNT);
    assertTrue("At least message " + MESSAGE_COUNT + " must be received, duplicates are expected, count=" + msgs.getMessageCount(), MESSAGE_COUNT <= msgs.getMessageCount());
}

88. LDAPSecurityTest#testSendTopic()

Project: activemq-artemis
File: LDAPSecurityTest.java
@Test
public void testSendTopic() throws Exception {
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
    Connection conn = factory.createQueueConnection("jdoe", "sunflower");
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    conn.start();
    Destination topic = sess.createTopic("TEST.BAR");
    MessageProducer producer = sess.createProducer(topic);
    MessageConsumer consumer = sess.createConsumer(topic);
    producer.send(sess.createTextMessage("test"));
    Message msg = consumer.receive(1000);
    assertNotNull(msg);
}

89. LDAPSecurityTest#testSendReceive()

Project: activemq-artemis
File: LDAPSecurityTest.java
@Test
public void testSendReceive() throws Exception {
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
    Connection conn = factory.createQueueConnection("jdoe", "sunflower");
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    conn.start();
    Destination queue = sess.createQueue("TEST.FOO");
    MessageProducer producer = sess.createProducer(queue);
    MessageConsumer consumer = sess.createConsumer(queue);
    producer.send(sess.createTextMessage("test"));
    Message msg = consumer.receive(1000);
    assertNotNull(msg);
}

90. JmsRollbackRedeliveryTest#populateDestination()

Project: activemq-artemis
File: JmsRollbackRedeliveryTest.java
private void populateDestination(final int nbMessages, final String destinationName, Connection connection) throws JMSException {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = session.createQueue(destinationName);
    MessageProducer producer = session.createProducer(destination);
    for (int i = 1; i <= nbMessages; i++) {
        producer.send(session.createTextMessage("<hello id='" + i + "'/>"));
    }
    producer.close();
    session.close();
}

91. JmsQueueTransactionTest#testCloseConsumer()

Project: activemq-artemis
File: JmsQueueTransactionTest.java
public void testCloseConsumer() throws Exception {
    Destination dest = session.createQueue(getSubject() + "?consumer.prefetchSize=0");
    producer = session.createProducer(dest);
    beginTx();
    producer.send(session.createTextMessage("message 1"));
    producer.send(session.createTextMessage("message 2"));
    commitTx();
    beginTx();
    consumer = session.createConsumer(dest);
    Message message1 = consumer.receive(1000);
    String text1 = ((TextMessage) message1).getText();
    assertNotNull(message1);
    assertEquals("message 1", text1);
    consumer.close();
    consumer = session.createConsumer(dest);
    Message message2 = consumer.receive(1000);
    String text2 = ((TextMessage) message2).getText();
    assertNotNull(message2);
    assertEquals("message 2", text2);
    commitTx();
}

92. JmsQueueCompositeSendReceiveTest#testSendReceive()

Project: activemq-artemis
File: JmsQueueCompositeSendReceiveTest.java
/**
    * Test if all the messages sent are being received.
    *
    * @throws Exception
    */
@Override
public void testSendReceive() throws Exception {
    super.testSendReceive();
    messages.clear();
    Destination consumerDestination = consumeSession.createQueue("FOO.BAR.HUMBUG2");
    LOG.info("Created  consumer destination: " + consumerDestination + " of type: " + consumerDestination.getClass());
    MessageConsumer consumer = null;
    if (durable) {
        LOG.info("Creating durable consumer");
        consumer = consumeSession.createDurableSubscriber((Topic) consumerDestination, getName());
    } else {
        consumer = consumeSession.createConsumer(consumerDestination);
    }
    consumer.setMessageListener(this);
    assertMessagesAreReceived();
    LOG.info("" + data.length + " messages(s) received, closing down connections");
}

93. JmsMultipleBrokersTestSupport#createDestination()

Project: activemq-artemis
File: JmsMultipleBrokersTestSupport.java
protected ActiveMQDestination createDestination(String name, boolean topic) throws JMSException {
    Destination dest;
    if (topic) {
        dest = new ActiveMQTopic(name);
        destinations.put(name, dest);
        return (ActiveMQDestination) dest;
    } else {
        dest = new ActiveMQQueue(name);
        destinations.put(name, dest);
        return (ActiveMQDestination) dest;
    }
}

94. JmsMessageConsumerTest#testSyncReceiveWithIgnoreExpirationChecks()

Project: activemq-artemis
File: JmsMessageConsumerTest.java
@Test
public void testSyncReceiveWithIgnoreExpirationChecks() throws Exception {
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerURI);
    factory.setConsumerExpiryCheckEnabled(false);
    Connection connection = factory.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = session.createQueue(name.getMethodName());
    MessageConsumer consumer = session.createConsumer(destination);
    MessageProducer producer = session.createProducer(destination);
    producer.setTimeToLive(TimeUnit.SECONDS.toMillis(2));
    connection.start();
    producer.send(session.createTextMessage("test"));
    // Allow message to expire in the prefetch buffer
    TimeUnit.SECONDS.sleep(4);
    assertNotNull(consumer.receive(1000));
    connection.close();
}

95. JmsMessageConsumerTest#testSyncReceiveWithExpirationChecks()

Project: activemq-artemis
File: JmsMessageConsumerTest.java
@Test
public void testSyncReceiveWithExpirationChecks() throws Exception {
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerURI);
    Connection connection = factory.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = session.createQueue(name.getMethodName());
    MessageConsumer consumer = session.createConsumer(destination);
    MessageProducer producer = session.createProducer(destination);
    producer.setTimeToLive(TimeUnit.SECONDS.toMillis(2));
    connection.start();
    producer.send(session.createTextMessage("test"));
    // Allow message to expire in the prefetch buffer
    TimeUnit.SECONDS.sleep(4);
    assertNull(consumer.receive(1000));
    connection.close();
}

96. JobSchedulerManagementTest#testRemoveNotScheduled()

Project: activemq-artemis
File: JobSchedulerManagementTest.java
@Test
public void testRemoveNotScheduled() throws Exception {
    Connection connection = createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    // Create the Browse Destination and the Reply To location
    Destination management = session.createTopic(ScheduledMessage.AMQ_SCHEDULER_MANAGEMENT_DESTINATION);
    MessageProducer producer = session.createProducer(management);
    try {
        // Send the remove request
        Message remove = session.createMessage();
        remove.setStringProperty(ScheduledMessage.AMQ_SCHEDULER_ACTION, ScheduledMessage.AMQ_SCHEDULER_ACTION_REMOVEALL);
        remove.setStringProperty(ScheduledMessage.AMQ_SCHEDULED_ID, new IdGenerator().generateId());
        producer.send(remove);
    } catch (Exception e) {
        fail("Caught unexpected exception during remove of unscheduled message.");
    }
}

97. ReconnectWithJMXEnabledTest#useConnection()

Project: activemq-artemis
File: ReconnectWithJMXEnabledTest.java
protected void useConnection(Connection connection) throws Exception {
    connection.setClientID("foo");
    connection.start();
    Session session = connection.createSession(transacted, authMode);
    Destination destination = createDestination();
    MessageConsumer consumer = session.createConsumer(destination);
    MessageProducer producer = session.createProducer(destination);
    Message message = session.createTextMessage("Hello World");
    producer.send(message);
    Thread.sleep(1000);
    consumer.close();
}

98. ProducerListenerTest#testConsumerEventsOnTemporaryDestination()

Project: activemq-artemis
File: ProducerListenerTest.java
public void testConsumerEventsOnTemporaryDestination() throws Exception {
    Session s = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
    Destination dest = useTopic ? s.createTemporaryTopic() : s.createTemporaryQueue();
    producerEventSource = new ProducerEventSource(connection, dest);
    producerEventSource.setProducerListener(this);
    producerEventSource.start();
    MessageProducer producer = s.createProducer(dest);
    assertProducerEvent(1, true);
    producer.close();
    assertProducerEvent(0, false);
}

99. ConsumerListenerTest#testConsumerEventsOnTemporaryDestination()

Project: activemq-artemis
File: ConsumerListenerTest.java
public void testConsumerEventsOnTemporaryDestination() throws Exception {
    Session s = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
    Destination dest = useTopic ? s.createTemporaryTopic() : s.createTemporaryQueue();
    consumerEventSource = new ConsumerEventSource(connection, dest);
    consumerEventSource.setConsumerListener(this);
    consumerEventSource.start();
    MessageConsumer consumer = s.createConsumer(dest);
    assertConsumerEvent(1, true);
    consumer.close();
    assertConsumerEvent(0, false);
}

100. ReceiveShipping#main()

Project: activemq-artemis
File: ReceiveShipping.java
public static void main(String[] args) throws Exception {
    ConnectionFactory factory = JmsHelper.createConnectionFactory("activemq-client.xml");
    Destination destination = ActiveMQDestination.fromAddress("jms.queue.shipping");
    try (Connection conn = factory.createConnection()) {
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumer = session.createConsumer(destination);
        consumer.setMessageListener(new MessageListener() {

            @Override
            public void onMessage(Message message) {
                System.out.println("Received Message: ");
                Order order = Jms.getEntity(message, Order.class);
                System.out.println(order);
            }
        });
        conn.start();
        Thread.sleep(1000000);
    }
}