• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java QueueBrowser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中javax.jms.QueueBrowser的典型用法代码示例。如果您正苦于以下问题:Java QueueBrowser类的具体用法?Java QueueBrowser怎么用?Java QueueBrowser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: testQueueBrowser

import javax.jms.QueueBrowser; //导入依赖的package包/类
@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());
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:23,代码来源:JMSUsecaseTest.java


示例2: testQueueBrowser

import javax.jms.QueueBrowser; //导入依赖的package包/类
public void testQueueBrowser() throws Exception {

      // Send a message to the broker.
      connection.start();
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      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());
   }
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:23,代码来源:JMSUsecaseTest.java


示例3: testGetQueue

import javax.jms.QueueBrowser; //导入依赖的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


示例4: testGetMessageSelector

import javax.jms.QueueBrowser; //导入依赖的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


示例5: testGetEnumeration

import javax.jms.QueueBrowser; //导入依赖的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


示例6: browseSelected

import javax.jms.QueueBrowser; //导入依赖的package包/类
@Override
public <T> T browseSelected(final Queue queue, final String messageSelector, final BrowserCallback<T> action)
		throws JmsException {

	Assert.notNull(action, "Callback object must not be null");
	return execute(new SessionCallback<T>() {
		@Override
		public T doInJms(Session session) throws JMSException {
			QueueBrowser browser = createBrowser(session, queue, messageSelector);
			try {
				return action.doInJms(session, browser);
			}
			finally {
				JmsUtils.closeQueueBrowser(browser);
			}
		}
	}, true);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:JmsTemplate.java


示例7: queueBrowser

import javax.jms.QueueBrowser; //导入依赖的package包/类
@Profile("browse")
@Bean
public QueueBrowser queueBrowser(Session queueSession, AMQPProperties amqpProperties, JMSProperties jmsProperties) {
	QueueBrowser messageBrowser = null;
	try {
		if(amqpProperties.amqpExchangeName != null && !"".equals(amqpProperties.amqpExchangeName)) {
			log.info("Not a valid option for queue browser");
			messageBrowser = queueSession.createBrowser(queueSession.createQueue(jmsProperties.queueName));
		}
		else {
			log.info("Creating QueueBrowser using JMS Queue obj for queueName="+jmsProperties.queueName);
			messageBrowser = queueSession.createBrowser(queueSession.createQueue(jmsProperties.queueName));
		}
	} catch (JMSException e) {
		e.printStackTrace();
	}
	return messageBrowser;
}
 
开发者ID:sdeeg-pivotal,项目名称:rabbitmq-jms-samples,代码行数:19,代码来源:BrowseConfig.java


示例8: setUp

import javax.jms.QueueBrowser; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    mockJmsSession = mock(Session.class);
    mockJmsQueueBrowser = mock(QueueBrowser.class);
    mockJmsTemplate = mock(JmsOperations.class);
    mockConversionService = mock(ConversionService.class);
    mockQueueMBean = mock(QueueViewMBean.class);
    mockErrorDao = mock(IVprSyncErrorDao.class);

    syncService = new SyncService();
    syncService.setConversionService(mockConversionService);
    syncService.setErrorDao(mockErrorDao);
    syncService.setJmsTemplate(mockJmsTemplate);
    syncService.setVprDeadLetterQueueMBean(mockQueueMBean);

    when(mockJmsTemplate.browse(eq(MessageDestinations.DEAD_LETTER_QUEUE), any(BrowserCallback.class))).thenAnswer(new ReturnsBrowserCallbackArgument<Object>(mockJmsSession, mockJmsQueueBrowser));
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:18,代码来源:JmsSyncErrorDaoTests.java


示例9: testBrowserNotAuthorized

import javax.jms.QueueBrowser; //导入依赖的package包/类
@Test(timeout = 30000)
public void testBrowserNotAuthorized() throws Exception {
   Connection connection = createConnection(noprivUser, noprivPass);

   try {
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      javax.jms.Queue queue = session.createQueue(getQueueName());
      try {
         QueueBrowser browser = session.createBrowser(queue);
         // Browser is not created until an enumeration is requesteda
         browser.getEnumeration();
         fail("Should not be able to consume here.");
      } catch (JMSSecurityException jmsSE) {
         IntegrationTestLogger.LOGGER.info("Caught expected exception");
      }
   } finally {
      connection.close();
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:20,代码来源:JMSConnectionWithSecurityTest.java


示例10: testCreateQueueBrowser

import javax.jms.QueueBrowser; //导入依赖的package包/类
@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());
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:17,代码来源:JMSQueueBrowserTest.java


示例11: testNoMessagesBrowserHasNoElements

import javax.jms.QueueBrowser; //导入依赖的package包/类
@Test(timeout = 40000)
public void testNoMessagesBrowserHasNoElements() 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());

   Enumeration<?> enumeration = browser.getEnumeration();
   assertFalse(enumeration.hasMoreElements());
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:20,代码来源:JMSQueueBrowserTest.java


示例12: testBroseOneInQueue

import javax.jms.QueueBrowser; //导入依赖的package包/类
@Test(timeout = 30000)
public void testBroseOneInQueue() throws Exception {
   Connection connection = createConnection();
   connection.start();

   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   javax.jms.Queue queue = session.createQueue(getQueueName());
   MessageProducer producer = session.createProducer(queue);
   producer.send(session.createTextMessage("hello"));
   producer.close();

   QueueBrowser browser = session.createBrowser(queue);
   Enumeration<?> enumeration = browser.getEnumeration();
   while (enumeration.hasMoreElements()) {
      Message m = (Message) enumeration.nextElement();
      assertTrue(m instanceof TextMessage);
      LOG.debug("Browsed message {} from Queue {}", m, queue);
   }

   browser.close();

   MessageConsumer consumer = session.createConsumer(queue);
   Message msg = consumer.receive(5000);
   assertNotNull(msg);
   assertTrue(msg instanceof TextMessage);
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:27,代码来源:JMSQueueBrowserTest.java


示例13: testBrowseAllInQueuePrefetchOne

import javax.jms.QueueBrowser; //导入依赖的package包/类
@Test(timeout = 60000)
public void testBrowseAllInQueuePrefetchOne() throws Exception {
   Connection connection = createConnection();
   connection.start();

   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   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);
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:27,代码来源:JMSQueueBrowserTest.java


示例14: testBrowseAllInQueueTxSession

import javax.jms.QueueBrowser; //导入依赖的package包/类
@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);
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:27,代码来源:JMSQueueBrowserTest.java


示例15: testBrowseExpiredMessages

import javax.jms.QueueBrowser; //导入依赖的package包/类
public void testBrowseExpiredMessages() throws Exception {
   JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1199/jmxrmi");
   JMXConnector connector = JMXConnectorFactory.connect(url, null);
   connector.connect();
   MBeanServerConnection connection = connector.getMBeanServerConnection();
   ObjectName name = new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost," + "destinationType=Queue,destinationName=TEST.Q");
   QueueViewMBean queueMbean = MBeanServerInvocationHandler.newProxyInstance(connection, name, QueueViewMBean.class, true);
   HashMap<String, String> headers = new HashMap<>();
   headers.put("timeToLive", Long.toString(2000));
   headers.put("JMSDeliveryMode", Integer.toString(DeliveryMode.PERSISTENT));
   queueMbean.sendTextMessage(headers, "test", "system", "manager");
   // allow message to expire on the queue
   TimeUnit.SECONDS.sleep(4);

   Connection c = new ActiveMQConnectionFactory("vm://localhost").createConnection("system", "manager");
   c.start();

   // browser consumer will force expiration check on addConsumer
   QueueBrowser browser = c.createSession(false, Session.AUTO_ACKNOWLEDGE).createBrowser(new ActiveMQQueue("TEST.Q"));
   assertTrue("no message in the q", !browser.getEnumeration().hasMoreElements());

   // verify dlq got the message, no security exception as brokers context is now used
   browser = c.createSession(false, Session.AUTO_ACKNOWLEDGE).createBrowser(new ActiveMQQueue("ActiveMQ.DLQ"));
   assertTrue("one message in the dlq", browser.getEnumeration().hasMoreElements());
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:26,代码来源:SecurityJMXTest.java


示例16: validateCounts

import javax.jms.QueueBrowser; //导入依赖的package包/类
public void validateCounts(int expectedWithCount,
                           int expectedWithoutCount,
                           int expectedAllCount) throws JMSException {
   QueueBrowser withPropertyBrowser = requestServerSession.createBrowser(theQueue, MSG_SEL_WITH_PROPERTY);
   QueueBrowser withoutPropertyBrowser = requestServerSession.createBrowser(theQueue, MSG_SEL_WITHOUT_PROPERTY);
   QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue);

   int withCount = getMessageCount(withPropertyBrowser, "withProperty ");
   int withoutCount = getMessageCount(withoutPropertyBrowser, "withoutProperty ");
   int allCount = getMessageCount(allBrowser, "allMessages ");

   withPropertyBrowser.close();
   withoutPropertyBrowser.close();
   allBrowser.close();

   assertEquals("Expected withCount to be " + expectedWithCount + " was " + withCount, expectedWithCount, withCount);
   assertEquals("Expected withoutCount to be " + expectedWithoutCount + " was " + withoutCount, expectedWithoutCount, withoutCount);
   assertEquals("Expected allCount to be " + expectedAllCount + " was " + allCount, expectedAllCount, allCount);
   LOG.info("withCount = " + withCount + "\n withoutCount = " + withoutCount + "\n allCount = " + allCount + "\n  = " + "\n");
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:21,代码来源:PurgeCommandTest.java


示例17: createBrowser

import javax.jms.QueueBrowser; //导入依赖的package包/类
/**
 * Create a browser
 *
 * @param queue The queue
 * @return The browser
 * @throws JMSException Thrown if an error occurs
 */
@Override
public QueueBrowser createBrowser(final Queue queue) 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 (ActiveMQRASession.trace) {
      ActiveMQRALogger.LOGGER.trace("createBrowser " + session + " queue=" + queue);
   }

   QueueBrowser result = session.createBrowser(queue);

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

   return result;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:28,代码来源:ActiveMQRASession.java


示例18: testQueueBrowsing

import javax.jms.QueueBrowser; //导入依赖的package包/类
/**
 * Checks that the QueueBrowser created by the <code>JMSConnectionMQ</code> class work correctly. 
 * @throws JMSException 
 * @throws InterruptedException 
 * @see JMSConnection#createQueueBrowser(ChannelID)
 */
public void testQueueBrowsing() throws JMSException, InterruptedException {
    QueueBrowser queueBrowser = conn.createQueueBrowser(Channels.getTheRepos());
    TestMessageConsumer mc = new TestMessageConsumer();
    conn.setListener(Channels.getTheRepos(), mc);        

    assertTrue("Empty queue had size > 0", queueBrowser.getEnumeration().hasMoreElements() == false);

    NetarkivetMessage nMsg = new TestMessage(Channels.getTheRepos(), Channels.getError(), "testQueueSendMessage");
    
    synchronized (mc) {
        conn.send(nMsg);
        assertTrue("Queue didn't have any messages after dispatching job", queueBrowser.getEnumeration().hasMoreElements() == true);
        mc.wait();
    }        
    
    assertEquals(
            "Arcrepos queue MessageConsumer should have received message.",
            nMsg.toString(), mc.nMsg.toString());
    
    assertTrue("Queue not empty after consumation of message", queueBrowser.getEnumeration().hasMoreElements() == false);
}
 
开发者ID:netarchivesuite,项目名称:netarchivesuite-svngit-migration,代码行数:28,代码来源:IntegrityTestSuite.java


示例19: browseEvents

import javax.jms.QueueBrowser; //导入依赖的package包/类
static void browseEvents(Session session, Queue queue, long limit) throws JMSException {
   QueueBrowser browser = session.createBrowser(queue);
   Enumeration msgs = browser.getEnumeration();
   int count = 0;
   Message lastMsg = null;
   while(msgs.hasMoreElements()) {
      Message msg = (Message) msgs.nextElement();
      lastMsg = msg;
      displayProperties(msg);
      count ++;
      if(count > limit)
         break;
   }
   System.out.printf("Scanned count: %d, lastMsg=%s\n", count, lastMsg);
   browser.close();

}
 
开发者ID:starksm64,项目名称:RaspberryPiBeaconParser,代码行数:18,代码来源:BrowseEvents.java


示例20: browseData

import javax.jms.QueueBrowser; //导入依赖的package包/类
private static List<Data<Long, Integer>> browseData(Session session, Queue destination) throws JMSException {
   List<Data<Long, Integer>> data = new ArrayList<>();
   QueueBrowser browser = session.createBrowser(destination);
   Enumeration<Message> msgs = browser.getEnumeration();
   Long minTime = Long.MAX_VALUE;
   Long maxTime = Long.MIN_VALUE;
   while (msgs.hasMoreElements()) {
      Message msg = msgs.nextElement();
      Integer rssi = msg.getIntProperty("rssi");
      Long time = msg.getLongProperty("time");
      minTime = Math.min(minTime, time);
      maxTime = Math.max(maxTime, time);
      data.add(new Data<>(time, rssi));
   }
   browser.close();
   long duration = maxTime - minTime;
   long hours = duration / (3600*1000);
   double days = hours / 24.0;
   System.out.printf("minTime=%s, maxTime=%s, hours=%d, days=%.2f\n", minTime, maxTime, hours, days);
   return data;
}
 
开发者ID:starksm64,项目名称:RaspberryPiBeaconParser,代码行数:22,代码来源:PlotBatteryRSSI.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EvaluationContextProvider类代码示例发布时间:2022-05-21
下一篇:
Java ParseUtil类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap