Hi All,

For my project I need to interact with Apache Zookeeper using Perl. For this I am using the Perl module

Net::ZooKeeper

Using this I am able to successfully crate the zk nodes but while triggering the watcher on that node the program is not working as I expected.

use Net::ZooKeeper qw(:node_flags :acls); my $zkh = Net::ZooKeeper->new('localhost:7000'); $zkh->create('/myzknode, 'active', 'flags' => ZOO_EPHEMERAL, 'acl' => +ZOO_OPEN_ACL_UNSAFE) or die("unable to create node /myzknode: " . $zk +h->get_error() . "\n"); print "node /myzknode has value: " . $zkh->get('/myzknode') . "\n";

Using the above code I am able to create a zookeeper node with the name ‘myzknode’ by assigning the value as ‘active’

After successful creation of zookeeper node from one instance of program, then the another instance of same program will run on another machine and try to create the same zookeeper node and fails, since the first instance already created the node with the same node.

Then the second instance should trigger one time watcher on that node, so if something happens to that node immediately zookeeper will generate an event to the program which triggered the watcher and then the watcher program will create the zookeeper node and star working further.

Here after creating the zookeeper node this I want to trigger a watcher on this node and catch the events like node deletion can be detected in my program. If anyone already worked on such thing please let me know.

I have used the following code to create a watcher, but its not working this watcher is coming our after some time and I am expecting the watcher to be keep watch on the zookeeper and catch the event happened on the node the event like 'NODE_DELETION'

my $watch = $zkh->watch('timeout' => 10000); $zkh->exists('/myzknode', 'watch' => $watch); if ($watch->wait()) { print "watch triggered on node /myzknode:\n"; print " event: $watch->{event}\n"; print " state: $watch->{state}\n"; } else { print "watch timed out after 10 seconds\n"; }

In this case the watcher code is coming to else loop and exiting from the program.


In reply to Perl interaction with apache Zookeeper by naiks

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.