public synchronized int size(){ ClientSession coreSession = null; int count = 0; try { coreSession = sf.createSession(false, false, false); ClientSession.QueueQuery result; result = coreSession.queueQuery(new SimpleString(queueName)); count = result.getMessageCount(); } catch (HornetQException e) { e.printStackTrace(); } finally { if (coreSession!= null ){ try { coreSession.close(); } catch (HornetQException e) { e.printStackTrace(); } } } return count; }
long messageCount = query.getMessageCount(); int count = 0; Thread.sleep(1000); query = session1.queueQuery(new SimpleString(queueName1)); messageCount = query.getMessageCount();
@Test public void testQueueQuery() throws Exception { cf = createSessionFactory(locator); ClientSession clientSession = cf.createSession(false, true, true); clientSession.createQueue("a1", queueName, false); clientSession.createConsumer(queueName); clientSession.createConsumer(queueName); ClientProducer cp = clientSession.createProducer("a1"); cp.send(clientSession.createMessage(true)); cp.send(clientSession.createMessage(true)); flushQueue(); QueueQuery resp = clientSession.queueQuery(new SimpleString(queueName)); Assert.assertEquals(new SimpleString("a1"), resp.getAddress()); Assert.assertEquals(2, resp.getConsumerCount()); Assert.assertEquals(2, resp.getMessageCount()); Assert.assertEquals(null, resp.getFilterString()); clientSession.close(); }
@Test public void testQueueQueryWithFilter() throws Exception { cf = createSessionFactory(locator); ClientSession clientSession = cf.createSession(false, true, true); clientSession.createQueue("a1", queueName, "foo=bar", false); clientSession.createConsumer(queueName); clientSession.createConsumer(queueName); QueueQuery resp = clientSession.queueQuery(new SimpleString(queueName)); Assert.assertEquals(new SimpleString("a1"), resp.getAddress()); Assert.assertEquals(2, resp.getConsumerCount()); Assert.assertEquals(0, resp.getMessageCount()); Assert.assertEquals(new SimpleString("foo=bar"), resp.getFilterString()); clientSession.close(); }