We solved this by asking the queue every time before we inserted
something how many message are there, e.g. in your producer do the
following:

public static synchronized void initJMX(long port) {
        try {
                JMXServiceURL url = new
JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:"+port+"/jmxrmi")
;
                        JMXConnector conn =
JMXConnectorFactory.connect(url);
                        mbs = conn.getMBeanServerConnection();
        } catch (Exception e) {
                log.error("Exception obtaining #messages in queue:" +
e.getMessage());
        }
                

    }
    
    public long getQueueSize(ActiveMQQueue destination) throws
Exception{
        try {
                String name = "org.apache.activemq" +
":Type=Queue,Destination=" + 
                destination.getQueueName() + ",BrokerName=localhost";
        
        ObjectName queueViewMBeanName = new ObjectName(name);
        
        if (mbs.isRegistered(queueViewMBeanName)) {
        
                QueueViewMBean queue = (QueueViewMBean)
MBeanServerInvocationHandler.newProxyInstance(mbs, queueViewMBeanName,
QueueViewMBean.class, true);
             
                
                long size = queue.getQueueSize();
                log.info("Queue: " + queueViewMBeanName + " now has: " +
size + " message(s)");
                return size;
        } else {
                log.error("Bean not registered");
                throw new Exception("Bean not registered");
        }
        } catch (Exception e) {
                log.error("Exception obtaining #messages in queue:" +
e.getMessage());
                throw new Exception(e);
        }
    }

Then you call the function in the produicer and decide if you can send
the message...

You also need to enable JMX on your JVM.

German



-----Original Message-----
From: itayke [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, January 30, 2007 4:49 AM
To: activemq-users@geronimo.apache.org
Subject: How to limit a queue capacity


Hi,

I like to limit the capacity of a queue (lets say to maximum of 5
messages).

1. How is it done?
2. what shall happen to a producer that will try to send the 6th message
to
this queue?

Thanks
-- 
View this message in context:
http://www.nabble.com/How-to-limit-a-queue-capacity-tf3142214.html#a8708
859
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Reply via email to