Thanks for the report, looks like something we need to address, would you mind going the extra step and adding a JIRA on this?

https://issues.apache.org/jira/browse/ZOOKEEPER

Thanks,

Patrick

kishore g wrote:
Hi All,

Zookeeper recipe queue code has a bug.

byte[] b = zk.getData(root + "/element" + min,
                                    false, stat);
                        zk.delete(root + "/element" + min, 0);

It throws an error saying the node element0 does not exists.

Node actually created  by producer was element0000000000. So along with min
minNodeName must be stored.

Here is the consume method that works.

    public int consume() throws KeeperException, InterruptedException{
        int retvalue = -1;
        Stat stat = null;

        // Get the first element available
        while (true) {
            synchronized (mutex) {
                List<String> list = zk.getChildren(root, true);
                if (list.size() == 0) {
                    System.out.println("Going to wait");
                    mutex.wait();
                } else {
                    Integer min = new Integer(list.get(0).substring(7));
                    String name = list.get(0);
                    for(String s : list){
                        Integer tempValue = new Integer(s.substring(7));
//                        System.out.println("Temporary value: " + s);
                        if(tempValue < min) {
                            min = tempValue;
                            name = s;
                        }
                    }
                    String zNode = root + "/" + name;
                    System.out.println("Temporary value: " + zNode);
                    byte[] b = zk.getData(zNode,false, stat);
                    zk.delete(zNode, 0);
                    ByteBuffer buffer = ByteBuffer.wrap(b);
                    retvalue = buffer.getInt();

                    return retvalue;
                }
            }
        }
    }


Also are there any performance numbers of zookeeeper based queues. How does
it compare with JMS.

thanks
Kishore G

Reply via email to