2009-05-20 60 views

回答

0

這是我落得這樣做:

Hashtable t = new Hashtable(); 
    t.put(Context.PROVIDER_URL, "localhost:1099"); 
    t.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); 
    Context ctx = new InitialContext(t); 
    Queue q = (Queue) ctx.lookup("/queue/DLQ"); 
    //---------------------------- 
    ConnectionFactory cf = (ConnectionFactory) ctx.lookup("/ConnectionFactory"); 
    Connection connection = cf.createConnection(); 
    Session session = connection.createSession(true, 0); 
    //--------------------------------- 
    MessageConsumer consumer = session.createConsumer(q); 
    connection.start(); 
    SpyObjectMessage m; 

    Queue originialDestination = null; 
//There can only be one in my case, but really you have to look it up every time. 
    MessageProducer producer = null; 
    while ((m = (SpyObjectMessage) consumer.receive(5000)) != null) { 
     Object o = m.getObject(); 
     Date messageDate = new Date(m.getJMSTimestamp()); 
     String originalQueue = m.getStringProperty("JBOSS_ORIG_DESTINATION"); 
      if (originialDestination == null) { 
       originialDestination = (Queue) ctx.lookup("/queue/" + 
originalQueue.substring(originalQueue.indexOf('.') + 1)); 
       producer = session.createProducer(originialDestination); 
      } 
      producer.send(session.createObjectMessage((Serializable) o)); 
     m.acknowledge(); 
    } 
    //session.commit(); //Uncomment to make this real. 
    connection.close(); 
    ctx.close(); 
1

看一看Hermes JMS。它是瀏覽JMS隊列和主題的開源工具。它可以重播消息,最終在代理的無法投遞的隊列中播放。

+0

愛馬仕JMS看起來不錯,謝謝! – Yishai 2009-05-21 16:58:53

0

注:我爲CodeStreet

工作

我們的產品「爲JMS ReplayService」正好建這個用例:搜索和檢索先前發佈的消息(n次交付) - JMS實際上是爲1次交付而設計的。

使用ReplayService for JMS,您可以配置WebLogic錄製以記錄發佈到您的主題或隊列的所有消息。通過基於Web的GUI,您可以搜索單個消息(通過子字符串,XPath或JMS選擇器),然後再次將它們重播到原始JMS目標。

有關詳細信息,請參見http://www.codestreet.com/marketdata/jms/jms_details.php