tags:

views:

837

answers:

2

Is there a way to resend expired messages in a JBoss 4.2.2 message queue? The issue is they exceeded their retry amounts, but now the problem is fixed, so is there a way to resend them?

In JBoss 3 they were just text files that you could move around. Now that it is stored in a database, how can you do it?

+1  A: 

Have a look at Hermes JMS. It's an open source tool for browsing JMS queues and topics. It can replay messages that end up on the broker's undeliverable queue.

Nat
Hermes JMS looks great, thanks!
Yishai
A: 

This is what I ended up doing:

    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();
Yishai