There is a task: there is a servlet that writes a message to one queue and waits for a response from another. Accordingly, since there can be a lot of calls to the servlet, he should wait for himself in the second response line and pull it back. Accordingly, since it is not standard to read messages from the queue, I use such a mechanism:
Enumeration messageEnumeration; ObjectMessage objectMessage; JMSContext jmsContext = mConnectionFactory.createContext(); QueueBrowser browser = jmsContext.createBrowser(mQueue); try { messageEnumeration = browser.getEnumeration(); mSc.log("start browser"); if (messageEnumeration != null){ mSc.log("messageEnumeration is not null "); if (!messageEnumeration.hasMoreElements()){ response.getWriter().append("there are no messages in the queue\n"); } else { while (messageEnumeration.hasMoreElements()){ mSc.log("into while"); Payment payment = new Payment(); objectMessage = (ObjectMessage) messageEnumeration.nextElement(); payment = (Payment) objectMessage.getObject(); response.getWriter().append(payment.getAcc() + " - " + payment.getNameClient() + " - " + payment.getSumma() + " " + payment.getCur()).append("\n"); if (payment.getAcc().equals("54321")){ // вот здесь надо удалить сообщение } } } } } catch (JMSException e) { // TODO Auto-generated catch block e.printStackTrace(); } Actually the question is how to delete a message that meets any criteria?