natbeat

package module
v0.0.0-...-521b7e7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2015 License: Apache-2.0 Imports: 10 Imported by: 9 modules, 9 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

NATBEAT

Natbeat registers a route with the gorouter. It conforms to the gorouter registration protocol, described here: https://github.com/cloudfoundry/gorouter#usage

Natbeat implements the ifrit.Runner interface: http://godoc.org/github.com/tedsuo/ifrit

Example Usage

The suggested usage is to create a backround heartbeat, which will silently wait for NATS to be accesible, and resart itself if it loses the connection.

// define the routes you would like to register
registration := natsbeat.RegistryMessage{
   URIs: []string{"foo.example.com","bar.example.com"},
   Host: "123.1.2.3",
   Port: 80,
}

// create a NATS client
natsClient := diegonats.NewClient()

// create a heartbeater that will restart itself whenever the nats connection is lost
heartbeater := natsbeat.NewBackgroundHeartBeat(natsClient, natsAddresses, natsUsername, natsPassword, logger, registration)

// begin heartbeating in the background
process := ifrit.Invoke(heartbeater)

// do your thing....

// signal the heartbeater with `os.Interrupt` to unregister and exit once you are done
process.Signal(os.Interrupt)
err := <-process.Wait()

// alternatively, signal with `os.Kill` to stop heartbeating immediately without unregistering
process.Signal(os.Kill)
err := <-process.Wait()

Documentation

Index

Constants

View Source
const (
	RouterGreetTopic      = "router.greet"
	RouterStartTopic      = "router.start"
	RouterRegisterTopic   = "router.register"
	RouterUnregisterTopic = "router.unregister"
)
View Source
const MaxConcurrentGreetings = 5
View Source
const NatsGreetRequestTimeout = 5 * time.Second

Variables

This section is empty.

Functions

func NewBackgroundHeartbeat

func NewBackgroundHeartbeat(natsClient diegonats.NATSClient, natsAddress, natsUsername, natsPassword string, logger lager.Logger, registration RegistryMessage) ifrit.RunFunc

Types

type GreetingMessage

type GreetingMessage struct {
	Id               string
	Hosts            []string
	RegisterInterval time.Duration
}

func (GreetingMessage) MarshalJSON

func (msg GreetingMessage) MarshalJSON() ([]byte, error)

func (*GreetingMessage) UnmarshalJSON

func (msg *GreetingMessage) UnmarshalJSON(data []byte) error

type Heartbeater

type Heartbeater struct {
	// contains filtered or unexported fields
}

func New

func New(natsClient diegonats.NATSClient, registryMessage RegistryMessage, initialInterval time.Duration, logger lager.Logger) *Heartbeater

func (Heartbeater) Run

func (h Heartbeater) Run(signals <-chan os.Signal, ready chan<- struct{}) error

type RegistryMessage

type RegistryMessage struct {
	URIs              []string `json:"uris"`
	Host              string   `json:"host"`
	Port              int      `json:"port"`
	App               string   `json:"app"`
	PrivateInstanceId string   `json:"private_instance_id"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址