Giter VIP home page Giter VIP logo

curator.go's Introduction

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/flier/curator.go

Using Curator

The Curator.go are available from github.com. You can easily include Curator.go into your code.

import (
	"github.com/flier/curator.go"
)

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:

curator.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:

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

client := curator.NewClient(connString, retryPolicy)

client.Start()
defer 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.:

client.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

lock := curator.NewInterProcessMutex(client, lockPath)

if ( lock.Acquire(maxWait, waitUnit) ) 
{
    defer lock.Release()

    // do some work inside of the critical section here
}

Leader Election

listener := 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
}))

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

Examples

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

  • leader Example leader selector code
  • cache Example PathChildrenCache usage
  • locking Example of using InterProcessMutex
  • discovery Example usage of the Curator's ServiceDiscovery
  • framework A few examples of how to use the CuratorFramework class

See the examples source repo for each example.

Components

  • Recipes Implementations of some of the common ZooKeeper "recipes". The implementations are built on top of the Curator Framework.
  • Framework The Curator Framework is a high-level API that greatly simplifies using ZooKeeper. It adds many features that build on ZooKeeper and handles the complexity of managing connections to the ZooKeeper cluster and retrying operations.
  • Utilities Various utilities that are useful when using ZooKeeper.
  • Client A replacement for the bundled ZooKeeper class that takes care of some low-level housekeeping and provides some useful utilities.
  • Errors How Curator deals with errors, connection issues, recoverable exceptions, etc.

curator.go's People

Contributors

flier avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

curator.go's Issues

abandoned project?

Seems like there has not been any activity for 11 months and there are some issues using this project as it is right now.

Naming is very unfortunate and doesn't allow for go get usage. Also the code does not work with the latest version of go-zookeeper.

To fix these issues I have created an organization "curator-go" with the curator project: https://github.com/curator-go/curator

If the original author has abandoned this project I will maintain under the new organization as I see the benefit of keeping this project alive. If the original author is still interested in maintenance I will immediately add him to the organization's users.

problem with repo name

Hi,
It seems that's go binary (tested with go 1.4.1 and 1.5.0) can't fetch repo because of its name. I forked you repo and renamed it: And it seems it fixed the "go get problem"
FYI, godoc also ignores your repo after I cloned it in $GOPATH.

[sheepkiller@playground ~]$ go get github.com/flier/curator.go
stat github.com/flier/curator.go: no such file or directory
[sheepkiller@playground ~]$ go get https://github.com/sheepkiller/curator-go
package https:/github.com/sheepkiller/curator-go: "https://" not allowed in import path
[sheepkiller@playground ~]$ go get github.com/sheepkiller/curator-go

github.com/sheepkiller/curator-go

go/src/github.com/sheepkiller/curator-go/framework.go:361: undefined: zk.StateSyncConnected
[sheepkiller@playground ~]$

thanks

Where is the NewLeaderSelectorListener()

Where is the function NewLeaderSelectorListener()
README.MD:
Leader Election

listener := 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
}))

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

Service Discovery support?

The examples section of the README mentions service discovery, but it looks like there isn't any actual code related to service discovery checked in yet. Is this work in-progress or otherwise planned?

I might work on it if not, but just wanted to make sure it wasn't already in-progress or done somewhere else before I started.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.