想试试JMS中的Broswer Queue的功能。打算在没有消费某个Queue的时候去看看Broswer里面有什么内容。模拟发送了一条消息后,并未在创建的同Queue的内容上找到应该有的一条消息,count的值总是0。不知道哪出逻辑出了问题。请熟悉JMS的同仁帮忙看看。代码如下:
import javax.jms.*;
import org.apache.activemq.ActiveMQConnectionFactory;
import java.util.Enumeration;public class Test {

public static void main(String[] args) throws Exception {
ActiveMQConnectionFactory conFactory = new ActiveMQConnectionFactory("username", "password", "tcp://localhost:61616");
QueueConnection qConnect = conFactory.createQueueConnection ("username", "password"); 
QueueSession qSession = qConnect.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);

org.apache.activemq.command.ActiveMQQueue testQueue = new org.apache.activemq.command.ActiveMQQueue();
testQueue.setPhysicalName("Broswer_Test");   
testQueue = (org.apache.activemq.command.ActiveMQQueue)qSession.createQueue("Broswer_Test");

        QueueSender qSender = qSession.createSender(testQueue);
        TextMessage textMsg = qSession.createTextMessage();
        textMsg.setText("xxxxxxx");
        qSender.send(textMsg);
        
QueueBrowser browser = qSession.createBrowser(testQueue);
Enumeration e = browser.getEnumeration();
        int count = 0;
while(e.hasMoreElements()){
System.out.println(count);
count++;
        }
System.out.println("count " + count);
}}

解决方案 »

  1.   

    接受了就更没戏了吧?
    被消费后,Queue上就没办法观察到了。而且我手动在JMS控制台上的指定的Queue上发送了消息(没有任何东西去消费它),还是变量不到。。
    奇怪啊,难道是ActiveMQ的问题。我想应该不是。。
    继续寻求正解
      

  2.   

    被消费后,Queue上就没办法观察到了。 而且我手动在JMS控制台上的指定的Queue上发送了消息(没有任何东西去消费它),还是变量不到。。