Java Code Examples for javax.jms.Session#createBrowser()

The following examples show how to use javax.jms.Session#createBrowser() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JmsQueueBrowserTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 40000)
public void testNoMessagesBrowserHasNoElements() throws Exception {
    connection = createAmqpConnection();
    connection.start();

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    assertNotNull(session);
    Queue queue = session.createQueue(getDestinationName());
    session.createConsumer(queue).close();

    QueueBrowser browser = session.createBrowser(queue);
    assertNotNull(browser);

    QueueViewMBean proxy = getProxyToQueue(getDestinationName());
    assertEquals(0, proxy.getQueueSize());

    Enumeration enumeration = browser.getEnumeration();
    assertFalse(enumeration.hasMoreElements());
}
 
Example 2
Source File: JMSUsecaseTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueueBrowser() throws Exception {
   // Send a message to the broker.
   connection.start();
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   ActiveMQDestination destination = createDestination(session, destinationType);
   MessageProducer producer = session.createProducer(destination);
   producer.setDeliveryMode(this.deliveryMode);
   sendMessages(session, producer, 5);
   producer.close();

   QueueBrowser browser = session.createBrowser((Queue) destination);
   Enumeration<?> enumeration = browser.getEnumeration();
   for (int i = 0; i < 5; i++) {
      Thread.sleep(100);
      assertTrue(enumeration.hasMoreElements());
      Message m = (Message) enumeration.nextElement();
      assertNotNull(m);
      assertEquals("" + i, ((TextMessage) m).getText());
   }
   assertFalse(enumeration.hasMoreElements());
}
 
Example 3
Source File: BrowserTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Test
public void emptyQueue() throws Exception
{
    Queue queue = createQueue(getTestName());
    Connection connection = getConnection();
    try
    {
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        QueueBrowser browser = session.createBrowser(queue);
        Enumeration enumeration = browser.getEnumeration();
        assertFalse(enumeration.hasMoreElements());
    }
    finally
    {
        connection.close();
    }
}
 
Example 4
Source File: JMSQueueBrowserTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 40000)
public void testCreateQueueBrowser() throws Exception {
   Connection connection = createConnection();
   connection.start();

   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   assertNotNull(session);
   javax.jms.Queue queue = session.createQueue(getQueueName());
   session.createConsumer(queue).close();

   QueueBrowser browser = session.createBrowser(queue);
   assertNotNull(browser);

   Queue queueView = getProxyToQueue(getQueueName());
   assertEquals(0, queueView.getMessageCount());
}
 
Example 5
Source File: JMSQueueBrowserTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 40000)
public void testBrowseAllInQueueTxSession() throws Exception {
   Connection connection = createConnection();
   connection.start();

   Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
   assertNotNull(session);
   javax.jms.Queue queue = session.createQueue(getQueueName());
   sendMessages(name.getMethodName(), 5, false);

   Queue queueView = getProxyToQueue(getQueueName());
   Wait.assertEquals(5, queueView::getMessageCount);

   QueueBrowser browser = session.createBrowser(queue);
   assertNotNull(browser);
   Enumeration<?> enumeration = browser.getEnumeration();
   int count = 0;
   while (enumeration.hasMoreElements()) {
      Message msg = (Message) enumeration.nextElement();
      assertNotNull(msg);
      LOG.debug("Recv: {}", msg);
      count++;
   }
   assertFalse(enumeration.hasMoreElements());
   assertEquals(5, count);
}
 
Example 6
Source File: ActiveMQRASession.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * Create a browser
 *
 * @param queue           The queue
 * @param messageSelector The message selector
 * @return The browser
 * @throws JMSException Thrown if an error occurs
 */
@Override
public QueueBrowser createBrowser(final Queue queue, final String messageSelector) throws JMSException {
   if (cri.getType() == ActiveMQRAConnectionFactory.TOPIC_CONNECTION || cri.getType() == ActiveMQRAConnectionFactory.XA_TOPIC_CONNECTION) {
      throw new IllegalStateException("Cannot create browser for javax.jms.TopicSession");
   }

   Session session = getSessionInternal();

   if (ActiveMQRALogger.LOGGER.isTraceEnabled()) {
      ActiveMQRALogger.LOGGER.trace("createBrowser " + session + " queue=" + queue + " selector=" + messageSelector);
   }

   QueueBrowser result = session.createBrowser(queue, messageSelector);

   if (ActiveMQRALogger.LOGGER.isTraceEnabled()) {
      ActiveMQRALogger.LOGGER.trace("createdBrowser " + session + " browser=" + result);
   }

   return result;
}
 
Example 7
Source File: JMSQueueBrowserTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 60000)
public void testBrowseAllInQueueZeroPrefetch() throws Exception {

   final int MSG_COUNT = 5;

   JmsConnection connection = (JmsConnection) createConnection();
   ((JmsDefaultPrefetchPolicy) connection.getPrefetchPolicy()).setAll(0);

   connection.start();

   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   assertNotNull(session);
   javax.jms.Queue queue = session.createQueue(getQueueName());
   sendMessages(name.getMethodName(), MSG_COUNT, false);

   Queue queueView = getProxyToQueue(getQueueName());
   Wait.assertEquals(MSG_COUNT, queueView::getMessageCount);

   QueueBrowser browser = session.createBrowser(queue);
   assertNotNull(browser);
   Enumeration<?> enumeration = browser.getEnumeration();
   int count = 0;
   while (count < MSG_COUNT && enumeration.hasMoreElements()) {
      Message msg = (Message) enumeration.nextElement();
      assertNotNull(msg);
      LOG.debug("Recv: {}", msg);
      count++;
   }

   LOG.debug("Received all expected message, checking that hasMoreElements returns false");
   assertFalse(enumeration.hasMoreElements());
   assertEquals(5, count);
}
 
Example 8
Source File: TibcoUtils.java    From iaf with Apache License 2.0 5 votes vote down vote up
protected static long getQueueFirstMessageAge(Session jSession,
		String queueName, String messageSelector, long currentTime,
		boolean warn) throws JMSException {
	QueueBrowser queueBrowser = null;
	try {
		Queue queue = jSession.createQueue(queueName);
		if (messageSelector == null) {
			queueBrowser = jSession.createBrowser(queue);
		} else {
			queueBrowser = jSession.createBrowser(queue, messageSelector);
		}
		Enumeration enm = queueBrowser.getEnumeration();
		if (enm.hasMoreElements()) {
			Object o = enm.nextElement();
			if (o instanceof Message) {
				Message msg = (Message) o;
				long jmsTimestamp = msg.getJMSTimestamp();
				return currentTime - jmsTimestamp;
			} else {
				if (warn) {
					log.warn("message was not of type Message, but ["
							+ o.getClass().getName() + "]");
				}
				return -2;
			}
		} else {
			return -1;
		}
	} finally {
		if (queueBrowser != null) {
			try {
				queueBrowser.close();
			} catch (JMSException e) {
				log.warn("Exception on closing queueBrowser", e);
			}
		}
	}
}
 
Example 9
Source File: JmsConsumerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testBrowserOnly() throws Exception {
   ((ActiveMQConnectionFactory) cf).setConsumerWindowSize(0);
   conn = cf.createConnection();

   Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
   jBossQueue = ActiveMQJMSClient.createQueue(JmsConsumerTest.Q_NAME);
   MessageProducer producer = session.createProducer(jBossQueue);
   int noOfMessages = 10;
   for (int i = 0; i < noOfMessages; i++) {
      TextMessage textMessage = session.createTextMessage("m" + i);
      textMessage.setIntProperty("i", i);
      producer.send(textMessage);
   }

   QueueBrowser browser = session.createBrowser(jBossQueue);
   Enumeration enumMessages = browser.getEnumeration();

   for (int i = 0; i < noOfMessages; i++) {
      Assert.assertTrue(enumMessages.hasMoreElements());
      TextMessage msg = (TextMessage) enumMessages.nextElement();
      Assert.assertNotNull(msg);
      Assert.assertEquals(i, msg.getIntProperty("i"));

   }

   Assert.assertFalse(enumMessages.hasMoreElements());

   conn.close();

   // Asserting delivering count is zero is bogus since messages might still be being delivered and expired at this
   // point
   // which can cause delivering count to flip to 1
}
 
Example 10
Source File: QueueBrowsingTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testMemoryLimit() throws Exception {
   broker.getSystemUsage().getMemoryUsage().setLimit(16 * 1024);

   int messageToSend = 370;

   ActiveMQQueue queue = new ActiveMQQueue("TEST");
   Connection connection = factory.createConnection();
   connection.start();
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageProducer producer = session.createProducer(queue);

   String data = "";
   for (int i = 0; i < 1024 * 2; i++) {
      data += "x";
   }

   for (int i = 0; i < messageToSend; i++) {
      producer.send(session.createTextMessage(data));
   }

   QueueBrowser browser = session.createBrowser(queue);
   Enumeration<?> enumeration = browser.getEnumeration();
   int received = 0;
   while (enumeration.hasMoreElements()) {
      Message m = (Message) enumeration.nextElement();
      received++;
      LOG.info("Browsed message " + received + ": " + m.getJMSMessageID());
   }

   browser.close();
   assertTrue("got at least maxPageSize", received >= maxPageSize);
}
 
Example 11
Source File: QueueBrowserIntegrationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout=30000)
public void testCreateQueueBrowserAndEnumeration() throws IOException, Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        Connection connection = testFixture.establishConnecton(testPeer);
        connection.start();

        testPeer.expectBegin();

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue("myQueue");

        // Expected the browser to create a consumer and send credit.
        testPeer.expectQueueBrowserAttach();
        testPeer.expectLinkFlow(false, equalTo(UnsignedInteger.valueOf(JmsDefaultPrefetchPolicy.DEFAULT_QUEUE_BROWSER_PREFETCH)));
        testPeer.expectDetach(true, true, true);

        QueueBrowser browser = session.createBrowser(queue);
        Enumeration<?> queueView = browser.getEnumeration();
        assertNotNull(queueView);

        browser.close();

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(3000);
    }
}
 
Example 12
Source File: BrowserTest.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Test
public void browserIsNonDestructive() throws Exception
{
    Queue queue = createQueue(getTestName());
    Connection connection = getConnection();
    try
    {
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer(queue);
        final Message message = session.createMessage();
        producer.send(message);
        producer.close();

        QueueBrowser browser = session.createBrowser(queue);
        Enumeration enumeration = browser.getEnumeration();
        assertTrue("Unexpected browser state", enumeration.hasMoreElements());

        Message browsedMessage = (Message) enumeration.nextElement();
        assertNotNull("No message returned by browser", browsedMessage);
        assertEquals("Unexpected JMSMessageID on browsed message", message.getJMSMessageID(), browsedMessage.getJMSMessageID());

        browser.close();

        MessageConsumer consumer = session.createConsumer(queue);
        Message consumedMessage = consumer.receive(getReceiveTimeout());
        assertNotNull("No message returned by consumer", consumedMessage);
        assertEquals("Unexpected JMSMessageID on consumed message", message.getJMSMessageID(), consumedMessage.getJMSMessageID());

        QueueBrowser browser2 = session.createBrowser(queue);
        Enumeration enumeration2 = browser2.getEnumeration();
        assertFalse("Unexpected browser state", enumeration2.hasMoreElements());
        browser2.close();
    }
    finally
    {
        connection.close();
    }
}
 
Example 13
Source File: QueueBrowserIntegrationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout=30000)
public void testCreateQueueBrowserClientAckSession() throws IOException, Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        Connection connection = testFixture.establishConnecton(testPeer);
        connection.start();

        testPeer.expectBegin();

        Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        Queue queue = session.createQueue("myQueue");

        DescribedType amqpValueNullContent = new AmqpValueDescribedType(null);

        // Expected the browser to create a consumer and send credit
        testPeer.expectQueueBrowserAttach();
        testPeer.expectLinkFlow(false, equalTo(UnsignedInteger.valueOf(JmsDefaultPrefetchPolicy.DEFAULT_QUEUE_BROWSER_PREFETCH)));
        // Then expect it to drain it when no message arrives before hasMoreElements is called,
        // at which point we send one, and a response flow to indicate the rest of the credit was drained.
        testPeer.expectLinkFlowRespondWithTransfer(null, null, null, null, amqpValueNullContent,
            1, true, true, equalTo(UnsignedInteger.valueOf(JmsDefaultPrefetchPolicy.DEFAULT_QUEUE_BROWSER_PREFETCH)), 1, true, false);
        // Expect the credit window to be opened again, but accounting for the message we just prefetched.
        testPeer.expectLinkFlow(false, equalTo(UnsignedInteger.valueOf(JmsDefaultPrefetchPolicy.DEFAULT_QUEUE_BROWSER_PREFETCH - 1)));
        testPeer.expectDetach(true, true, true);

        QueueBrowser browser = session.createBrowser(queue);
        Enumeration<?> queueView = browser.getEnumeration();
        assertNotNull(queueView);
        assertTrue(queueView.hasMoreElements());

        browser.close();

        testPeer.expectEnd();
        session.close();

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(3000);
    }
}
 
Example 14
Source File: JMSQueueBrowserTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 60000)
public void testBrowseAllInQueueSmallPrefetch() throws Exception {
   Connection connection = createConnection();
   connection.start();

   final int MSG_COUNT = 30;

   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   assertNotNull(session);
   javax.jms.Queue queue = session.createQueue(getQueueName());
   sendMessages(name.getMethodName(), MSG_COUNT, false);

   Queue queueView = getProxyToQueue(getQueueName());
   Wait.assertEquals(MSG_COUNT, queueView::getMessageCount);

   QueueBrowser browser = session.createBrowser(queue);
   assertNotNull(browser);
   Enumeration<?> enumeration = browser.getEnumeration();
   int count = 0;
   while (enumeration.hasMoreElements()) {
      Message msg = (Message) enumeration.nextElement();
      assertNotNull(msg);
      LOG.debug("Recv: {}", msg);
      count++;
   }
   assertFalse(enumeration.hasMoreElements());
   assertEquals(MSG_COUNT, count);
}
 
Example 15
Source File: SuperTestPayload.java    From jqm with Apache License 2.0 4 votes vote down vote up
@Override
public void start()
{
	System.out.println("Thread context class loader is: " + Thread.currentThread().getContextClassLoader());
	System.out.println("Class class loader used for loading test class is: " + this.getClass().getClassLoader());
	int nb = 0;

	try
	{
		// Get the QCF
		Object o = NamingManager.getInitialContext(null).lookup("jms/qcf");
		System.out.println("Received a " + o.getClass());

		// Do as cast & see if no errors
		QueueConnectionFactory qcf = (QueueConnectionFactory) o;

		// Get the Queue
		Object p = NamingManager.getInitialContext(null).lookup("jms/testqueue");
		System.out.println("Received a " + p.getClass());
		Queue q = (Queue) p;

		// Now that we are sure that JNDI works, let's write a message
		System.out.println("Opening connection & session to the broker");
		Connection connection = qcf.createConnection();
		connection.start();
		Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);

		System.out.println("Creating producer");
		MessageProducer producer = session.createProducer(q);
		TextMessage message = session.createTextMessage("HOUBA HOP. SIGNED: MARSUPILAMI");

		System.out.println("Sending message");
		producer.send(message);
		producer.close();
		session.commit();
		System.out.println("A message was sent to the broker");

		// Browse and check the message is there
		Connection connection2 = qcf.createConnection();
		connection2.start();
		Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
		QueueBrowser qb = session2.createBrowser(q);
		Enumeration<TextMessage> msgs = qb.getEnumeration();
		while (msgs.hasMoreElements())
		{
			TextMessage msg = msgs.nextElement();
			System.out.println("Message received: " + msg.getText());
			nb++;
		}
		System.out.println("Browsing will end here");
		qb.close();
		System.out.println("End of browsing. Nb of message read: " + nb);

		// We are done!
		connection.close();
		connection2.close();

	} catch (Exception e)
	{
		e.printStackTrace();
	}

	if (nb == 0)
		throw new RuntimeException("test has failed - no messages were received.");
}
 
Example 16
Source File: JmsQueueBrowserTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
/**
 * Tests the queue browser. Browses the messages then the consumer tries to receive them. The messages should still
 * be in the queue even when it was browsed.
 *
 * @throws Exception
 */
public void testReceiveBrowseReceive() throws Exception {
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   ActiveMQQueue destination = new ActiveMQQueue("TEST");
   MessageProducer producer = session.createProducer(destination);
   MessageConsumer consumer = session.createConsumer(destination);
   connection.start();

   Message[] outbound = new Message[]{session.createTextMessage("First Message"), session.createTextMessage("Second Message"), session.createTextMessage("Third Message")};

   // lets consume any outstanding messages from previous test runs
   while (consumer.receive(1000) != null) {
   }

   producer.send(outbound[0]);
   producer.send(outbound[1]);
   producer.send(outbound[2]);

   // Get the first.
   assertEquals(outbound[0], consumer.receive(1000));
   consumer.close();

   QueueBrowser browser = session.createBrowser(destination);
   Enumeration<?> enumeration = browser.getEnumeration();

   // browse the second
   assertTrue("should have received the second message", enumeration.hasMoreElements());
   assertEquals(outbound[1], enumeration.nextElement());

   // browse the third.
   assertTrue("Should have received the third message", enumeration.hasMoreElements());
   assertEquals(outbound[2], enumeration.nextElement());

   // There should be no more.
   boolean tooMany = false;
   while (enumeration.hasMoreElements()) {
      LOG.info("Got extra message: " + ((TextMessage) enumeration.nextElement()).getText());
      tooMany = true;
   }
   assertFalse(tooMany);
   browser.close();

   // Re-open the consumer.
   consumer = session.createConsumer(destination);
   // Receive the second.
   assertEquals(outbound[1], consumer.receive(1000));
   // Receive the third.
   assertEquals(outbound[2], consumer.receive(1000));
   consumer.close();
}
 
Example 17
Source File: JmsQueueBrowserTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@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();
}
 
Example 18
Source File: QueueBrowserIntegrationTest.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
@Test(timeout=30000)
public void testCreateQueueBrowserTransactedSession() throws IOException, Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        Connection connection = testFixture.establishConnecton(testPeer);
        connection.start();

        testPeer.expectBegin();
        testPeer.expectCoordinatorAttach();

        // First expect an unsettled 'declare' transfer to the txn coordinator, and
        // reply with a declared disposition state containing the txnId.
        Binary txnId = new Binary(new byte[]{ (byte) 1, (byte) 2, (byte) 3, (byte) 4});
        TransferPayloadCompositeMatcher declareMatcher = new TransferPayloadCompositeMatcher();
        declareMatcher.setMessageContentMatcher(new EncodedAmqpValueMatcher(new Declare()));
        testPeer.expectTransfer(declareMatcher, nullValue(), new Declared().setTxnId(txnId), true);

        Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
        Queue queue = session.createQueue("myQueue");

        DescribedType amqpValueNullContent = new AmqpValueDescribedType(null);

        // Expect the browser enumeration to create a underlying consumer
        testPeer.expectQueueBrowserAttach();
        // Expect initial credit to be sent
        testPeer.expectLinkFlow(false, equalTo(UnsignedInteger.valueOf(JmsDefaultPrefetchPolicy.DEFAULT_QUEUE_BROWSER_PREFETCH)));
        // Then expect it to drain it when no message arrives before hasMoreElements is called,
        // at which point we send one, and a response flow to indicate the rest of the credit was drained.
        testPeer.expectLinkFlowRespondWithTransfer(null, null, null, null, amqpValueNullContent,
            1, true, true, equalTo(UnsignedInteger.valueOf(JmsDefaultPrefetchPolicy.DEFAULT_QUEUE_BROWSER_PREFETCH)), 1, true, false);
        // Expect a non-draining flow to reopen the credit window again afterwards, but accounting for the message we just prefetched.
        testPeer.expectLinkFlow(false, equalTo(UnsignedInteger.valueOf(JmsDefaultPrefetchPolicy.DEFAULT_QUEUE_BROWSER_PREFETCH - 1)));

        QueueBrowser browser = session.createBrowser(queue);
        Enumeration<?> queueView = browser.getEnumeration();
        assertNotNull(queueView);
        assertTrue(queueView.hasMoreElements());

        // Browser should close without delay as it does not participate in the TX
        testPeer.expectDetach(true, true, true);

        browser.close();

        testPeer.waitForAllHandlersToComplete(3000);
    }
}
 
Example 19
Source File: BrowserTest.java    From activemq-artemis with Apache License 2.0 3 votes vote down vote up
@Test
public void testBrowse() throws Exception {
   conn = getConnectionFactory().createConnection();

   Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

   MessageProducer producer = session.createProducer(queue1);

   QueueBrowser browser = session.createBrowser(queue1);

   ProxyAssertSupport.assertEquals(browser.getQueue(), queue1);

   ProxyAssertSupport.assertNull(browser.getMessageSelector());

   Enumeration<Message> en = browser.getEnumeration();

   conn.start();

   Message m = session.createMessage();
   m.setIntProperty("cnt", 0);
   producer.send(m);
   Message m2 = en.nextElement();

   Assert.assertNotNull(m2);

   drainDestination(getConnectionFactory(), queue1);
}
 
Example 20
Source File: JmsTemplate.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Create a JMS MessageProducer for the given Session and Destination,
 * configuring it to disable message ids and/or timestamps (if necessary).
 * <p>Delegates to {@link #doCreateProducer} for creation of the raw
 * JMS MessageProducer.
 * @param session the JMS Session to create a QueueBrowser for
 * @param queue the JMS Queue to create a QueueBrowser for
 * @param messageSelector the message selector for this consumer (can be {@code null})
 * @return the new JMS QueueBrowser
 * @throws JMSException if thrown by JMS API methods
 * @see #setMessageIdEnabled
 * @see #setMessageTimestampEnabled
 */
protected QueueBrowser createBrowser(Session session, Queue queue, @Nullable String messageSelector)
		throws JMSException {

	return session.createBrowser(queue, messageSelector);
}