How to manage or manage a JMS queue? For instance. reordering messages in a queue, deleting a message, etc.

I am using HornetQ with JBoss6 on Linux OS, Can someone tell me how we can manage the JMS queue to delete a message or change the message order, Details of MessageConsumers associated with the queue?

Which approach is best suited for such a requirement? Any suggestion is appreciated.

Thank.

+3
source share
1 answer

A queue is a simple concept - several sources write to a queue, and one consumer reads the messages one by one in the order in which they were received. An attempt to introduce random access confuses the concept and goes against the intent with the queue.

, , bean (MDB), : MDB Q, Q'.

:

Q -> orignal consumer

:

Q -> your filtering and sorting MDB -> Q' -> original consumer

, , .

. MDB , ( Java Enterprise Edition 6 tutorial). MDB.

// MDB to consume messages on the original queue
@MessageDriven(mappedName="jms/IncomingQueue", activationConfig =  {
        @ActivationConfigProperty(propertyName = "acknowledgeMode",
                                  propertyValue = "Auto-acknowledge"),
        @ActivationConfigProperty(propertyName = "destinationType",
                                  propertyValue = "javax.jms.Queue")
    })
public class MyMDB implements MessageListener {
    @EJB
    private MessageFilter messageFilter;

    public void onMessage(Message message) {
        // pass on to MessageFilter bean for processing
        messageFilter.filter(message);
    }
}

// singleton bean to filter and sort messages, then re-publish to the original consumer
// if singleton doesn't work in your environment then you might have to persist the
// messages using e.g. JPA
@Singleton
public class MessageFilter {
    @Resource(name="jms/OutgoingQueue")
    Queue outgoingQueue;

    @Resource(name="jms/QueueConnectionFactory")
    QueueConnectionFactory qcf;

    // accept incoming message from the MDB
    void filter(Message message) {
        // filter and sort messages
        ...

        // send to queue read by the original consumer
        send(message);            
    }

    // send message to the filtered & sorted queue for the original consumer
    void send(Message message) {
        QueueConnection queueConnection = qcf.createQueueConnection();
        QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        QueueSender queueSender = queueSession(outgoingQueue);

        queueSender.send(message);
    }
}

Java EE 6 singleton beans, .

+1

All Articles