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


Java QueueBrowser类代码示例

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


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


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