当前位置: 首页>>代码示例>>Java>>正文


Java QueueSession.createBrowser方法代码示例

本文整理汇总了Java中javax.jms.QueueSession.createBrowser方法的典型用法代码示例。如果您正苦于以下问题:Java QueueSession.createBrowser方法的具体用法?Java QueueSession.createBrowser怎么用?Java QueueSession.createBrowser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.jms.QueueSession的用法示例。


在下文中一共展示了QueueSession.createBrowser方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testGetQueue

import javax.jms.QueueSession; //导入方法依赖的package包/类
@Test
public void testGetQueue() throws JMSException {
    JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
    QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createTemporaryQueue();
    QueueBrowser browser = session.createBrowser(queue);

    assertNotNull(browser.getQueue());

    browser.close();
    browser.close();

    try {
        browser.getQueue();
        fail("Should not be able to use a closed browser");
    } catch (IllegalStateException ise) {
    }
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:19,代码来源:JmsQueueBrowserTest.java

示例2: testGetQueueBrowser

import javax.jms.QueueSession; //导入方法依赖的package包/类
@Test
public void testGetQueueBrowser() throws JMSException {
    JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
    QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createTemporaryQueue();
    JmsPoolQueueBrowser browser = (JmsPoolQueueBrowser) session.createBrowser(queue);

    assertNotNull(browser.getQueueBrowser());

    browser.close();

    try {
        browser.getQueueBrowser();
        fail("Should not be able to use a closed browser");
    } catch (IllegalStateException ise) {
    }
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:18,代码来源:JmsQueueBrowserTest.java

示例3: testGetMessageSelector

import javax.jms.QueueSession; //导入方法依赖的package包/类
@Test
public void testGetMessageSelector() throws JMSException {
    JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
    QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createTemporaryQueue();
    QueueBrowser browser = session.createBrowser(queue, "color = red");

    assertNotNull(browser.getMessageSelector());
    assertEquals("color = red", browser.getMessageSelector());

    browser.close();

    try {
        browser.getMessageSelector();
        fail("Should not be able to use a closed browser");
    } catch (IllegalStateException ise) {
    }
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:19,代码来源:JmsQueueBrowserTest.java

示例4: testGetEnumeration

import javax.jms.QueueSession; //导入方法依赖的package包/类
@Test
public void testGetEnumeration() throws JMSException {
    JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
    QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createTemporaryQueue();
    QueueBrowser browser = session.createBrowser(queue);

    assertNotNull(browser.getEnumeration());

    browser.close();

    try {
        browser.getEnumeration();
        fail("Should not be able to use a closed browser");
    } catch (IllegalStateException ise) {
    }
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:18,代码来源:JmsQueueBrowserTest.java

示例5: testToString

import javax.jms.QueueSession; //导入方法依赖的package包/类
@Test
public void testToString() throws JMSException {
    JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
    QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createTemporaryQueue();
    QueueBrowser browser = session.createBrowser(queue);

    assertNotNull(browser.toString());
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:10,代码来源:JmsQueueBrowserTest.java

示例6: getBeans

import javax.jms.QueueSession; //导入方法依赖的package包/类
/**
 * Read the status beans from any queue.
 * Returns a list of optionally date-ordered beans in the queue.
 *
 * @param uri
 * @param queueName
 * @param clazz
 * @param monitor
 * @return
 * @throws Exception
 */
public List<T> getBeans(final URI uri, final String queueName, final Class<T> beanClass) throws Exception {

	QueueConnection qCon = null;
	try {
		QueueConnectionFactory connectionFactory = (QueueConnectionFactory)service.createConnectionFactory(uri);
		qCon  = connectionFactory.createQueueConnection(); // This times out when the server is not there.
		QueueSession    qSes  = qCon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
		Queue queue   = qSes.createQueue(queueName);
		qCon.start();

		QueueBrowser qb = qSes.createBrowser(queue);
		@SuppressWarnings("rawtypes")
		Enumeration  e  = qb.getEnumeration();


		final Collection<T> list;
		if (comparator!=null) {
			list = new TreeSet<T>(comparator);
		} else {
			list = new ArrayList<T>(17);
		}

		while(e.hasMoreElements()) {
			Message m = (Message)e.nextElement();
			if (m==null) continue;
			if (m instanceof TextMessage) {
				TextMessage t = (TextMessage)m;
				String json   = t.getText();
				@SuppressWarnings("unchecked")
				final Class<T> statusBeanClass = (Class<T>) StatusBean.class;
				try {
					final T bean = (T)service.unmarshal(json, beanClass != null ? beanClass : statusBeanClass);
					list.add(bean);

				} catch (Exception unmarshallable) {
					System.out.println("Removing old message "+json);
					String jMSMessageID = m.getJMSMessageID();
					if (jMSMessageID!=null) {
						MessageConsumer consumer = qSes.createConsumer(queue, "JMSMessageID = '"+jMSMessageID+"'");
						Message ignored = consumer.receive(1000);
						consumer.close();
						System.out.println("Removed");
					}

				}
			}
		}
		return list instanceof List ? (List<T>)list : new ArrayList<T>(list);

	} finally {
		if (qCon!=null) qCon.close();
	}

}
 
开发者ID:eclipse,项目名称:scanning,代码行数:66,代码来源:QueueReader.java

示例7: test

import javax.jms.QueueSession; //导入方法依赖的package包/类
@Test(timeout = 5 * 60 * 1000)
public void test() throws Throwable {
   executeCommand("bundle:list");

   withinReason(new Callable<Boolean>() {
      @Override
      public Boolean call() throws Exception {
         assertTrue("artemis bundle installed", verifyBundleInstalled("artemis-server-osgi"));
         return true;
      }
   });

   Object service = waitForService("(objectClass=org.apache.activemq.artemis.core.server.ActiveMQServer)", 30000);
   assertNotNull(service);
   LOG.info("have service " + service);

   executeCommand("service:list -n");

   Connection connection = null;
   try {
      JmsConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:5672");
      connection = factory.createConnection(USER, PASSWORD);
      connection.start();

      QueueSession sess = (QueueSession) connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
      Queue queue = sess.createQueue("exampleQueue");
      MessageProducer producer = sess.createProducer(queue);
      producer.send(sess.createTextMessage("TEST"));

      // Test browsing
      try (QueueBrowser browser = sess.createBrowser(queue)) {
         Enumeration messages = browser.getEnumeration();
         while (messages.hasMoreElements()) {
            messages.nextElement();
         }
      }

      // Test management
      Queue managementQueue = sess.createQueue("activemq.management");
      QueueRequestor requestor = new QueueRequestor(sess, managementQueue);
      connection.start();
      TextMessage m = sess.createTextMessage();
      m.setStringProperty("_AMQ_ResourceName", "broker");
      m.setStringProperty("_AMQ_OperationName", "getQueueNames");
      m.setText("[\"ANYCAST\"]");
      Message reply = requestor.request(m);
      String json = ((TextMessage) reply).getText();
      JsonArray array = Json.createReader(new StringReader(json)).readArray();
      List<JsonString> queues = (List<JsonString>) array.get(0);
      assertNotNull(queues);
      assertFalse(queues.isEmpty());

      MessageConsumer consumer = sess.createConsumer(queue);
      Message msg = consumer.receive(5000);
      assertNotNull(msg);
   } finally {
      if (connection != null) {
         connection.close();
      }
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:62,代码来源:ArtemisFeatureTest.java


注:本文中的javax.jms.QueueSession.createBrowser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。