本文整理匯總了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) {
}
}
示例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) {
}
}
示例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) {
}
}
示例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) {
}
}
示例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());
}
示例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();
}
}
示例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();
}
}
}