kikinteractive/curator-go

Name: curator-go

Owner: Kik Interactive

Description: A partial conversion of Curator for golang: a library that simplifies interaction w. zookeeper

Forked from: curator-go/curator

Created: 2017-04-27 09:35:58.0

Updated: 2017-04-27 09:38:29.0

Pushed: 2017-06-29 20:05:31.0

Homepage:

Size: 212

Language: Go

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Note: this is (obviously) a fork from the original curator-go. This fork was created to host a missing recipe - the ConnectionWrapper. rerfer to this commit - 8a0724b587dee7a06671fc12970f1d534bf410bd. The connection wrapper is a gutted version of the cache recipe. Most of the functionality was stripped away leaving just a wrapper around the zookeeper connection, which allows listening to connection-level events (reconnection etc). This functionality was needed for the xiphias-go-registry repo.

What is Curator?

Curator n ?kyoor???t?r: a keeper or custodian of a museum or other collection - A ZooKeeper Keeper.

curator

What is curator-go?

Curator-go is a Golang porting for Curator, which base on the go-zookeeper.

Getting Started

Learn ZooKeeper

Curator-go users are assumed to know ZooKeeper. A good place to start is ZooKeeper Getting Started Guide

Install Curator-go

$ go get github.com/curator-go/curator

Using Curator

Curator-go is available from github.com. You can easily include Curator-go into your code.

rt (
"github.com/curator-go/curator"

Getting a Connection

Curator uses Fluent Style. If you haven't used this before, it might seem odd so it's suggested that you familiarize yourself with the style.

Curator connection instances (CuratorFramework) are allocated from the CuratorFrameworkBuilder. You only need one CuratorFramework object for each ZooKeeper cluster you are connecting to:

tor.NewClient(connString, retryPolicy)

This will create a connection to a ZooKeeper cluster using default values. The only thing that you need to specify is the retry policy. For most cases, you should use:

yPolicy := curator.NewExponentialBackoffRetry(time.Second, 3, 15*time.Second)

nt := curator.NewClient(connString, retryPolicy)

nt.Start()
r client.Close()

The client must be started (and closed when no longer needed).

Calling ZooKeeper Directly

Once you have a CuratorFramework instance, you can make direct calls to ZooKeeper in a similar way to using the raw ZooKeeper object provided in the ZooKeeper distribution. E.g.:

nt.Create().ForPathWithData(path, payload)

The benefit here is that Curator manages the ZooKeeper connection and will retry operations if there are connection problems.

Recipes
Distributed Lock
 := curator.NewInterProcessMutex(client, lockPath)

 lock.Acquire(maxWait, waitUnit) )

defer lock.Release()

// do some work inside of the critical section here

Leader Election
ener := curator.NewLeaderSelectorListener(func(CuratorFramework client) error {
// this callback will get called when you are the leader
// do whatever leader work you need to and only exit
// this method when you want to relinquish leadership


ctor := curator.NewLeaderSelector(client, path, listener)
ctor.AutoRequeue()  // not required, but this is behavior that you will probably expect
ctor.Start()

Examples

This module contains example usages of various Curator features. Each directory in the module is a separate example.

See the examples source repo for each example.

Components


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.