Ravi Rao
Ravi Rao

Reputation: 401

Implementing MDB Pool Listener in JBoss JMS

I've an application deployed in JBoss with multiple MDBs deployed using JBoss JMS implementation, each one with a different configuration of MDB Pool Size. I was looking forward to some kind of mechanism where we can have a listener on each MDB Pool size where we can check if at any point all instances from the MDB pool are getting utilized. This will help in analyzing and configuring the appropriate MDB pool size for each MDB.

Upvotes: 1

Views: 651

Answers (1)

Uwe Hehn
Uwe Hehn

Reputation: 11

We use Jamon to monitor instances of MDBs, like this:

    @MessageDriven
@TransactionManagement(value = TransactionManagementType.CONTAINER)
@TransactionAttribute(value = TransactionAttributeType.REQUIRED)
@ResourceAdapter("wmq.jmsra.rar")
@AspectDomain("YourDomainName")
public class YourMessageDrivenBean implements MessageListener
{
    // jamon package constant
    protected static final String WB_ONMESSAGE = "wb.onMessage";

    // instance counter
    private static AtomicInteger counter = new AtomicInteger(0);
    private int instanceIdentifier = 0;

    @Resource
    MessageDrivenContext ctx;

    @Override
    public void onMessage(Message message)
    {
        final Monitor monall = MonitorFactory.start(WB_ONMESSAGE);
        final Monitor mon = MonitorFactory.start(WB_ONMESSAGE + "." + toString()
                + "; mdb instance identifier=" + instanceIdentifier);

        try {
// process your  message here
            }

        } catch (final Exception x) {
            log.error("Error onMessage " + x.getMessage(), x);
            ctx.setRollbackOnly();
        } finally {
            monall.stop();
            mon.stop();
        }

    }

    @PostConstruct
    public void init()
    {
        instanceIdentifier = counter.incrementAndGet();
        log.debug("constructed instance #" + instanceIdentifier);
    }
}

You can then see in the Jamon-Monitor every created instance of your MDB.

Upvotes: 1

Related Questions