Skip to content
This repository was archived by the owner on Feb 7, 2020. It is now read-only.

Commit acdc39b

Browse files
authored
Merge pull request #6 from ripienaar/010
(misc) Release 0.1.0
2 parents ba45b07 + 6aaf4d5 commit acdc39b

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
|Date |Issue |Description |
22
|----------|------|---------------------------------------------------------------------------------------------------------|
3+
|2018/08/27| |Release 0.1.0 |
4+
|2018/08/27|4 |Add `Identity()` to all events to extract the sender |
35
|2018/08/26| |Release 0.0.2 |
46
|2018/08/26|1 |Add shutdown events |
57
|2018/08/26| |Release 0.0.1 |

README.md

+87-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,89 @@
11
# Choria Lifecycle Events
22

3-
This package create and view Choria Lifecycle Events
3+
This package create and view Choria Lifecycle Events
4+
5+
These lifecycle events are published to the `choria.lifecycle.event.<type>.<component>` topic structure of the middleware and contains small JSON documents that informs listeners about significant life cycle events of Choria components.
6+
7+
[![GoDoc](https://godoc.org/github.com/choria-io/go-lifecycle?status.svg)](https://godoc.org/github.com/choria-io/go-lifecycle) [![CircleCI](https://circleci.com/gh/choria-io/go-lifecycle/tree/master.svg?style=svg)](https://circleci.com/gh/choria-io/go-lifecycle/tree/master)
8+
9+
## Supported Events
10+
11+
|Event|Description|
12+
|-----|-----------|
13+
|Startup|Event to emit when components start, requires `Identity()`, `Component()` and `Version()` options|
14+
|Shutdown|Event to emit when components shut down, requires `Identity()` and `Component()` options|
15+
16+
#### Sample Events
17+
### Schemas
18+
19+
Event Schemas are stored in the [Choria Schemas repository](https://github.com/choria-io/schemas/tree/master/choria/lifecycle).
20+
21+
#### Startup
22+
23+
```json
24+
{
25+
"protocol":"choria:lifecycle:startup:1",
26+
"identity":"c1.example.net",
27+
"version":"0.6.0",
28+
"timestamp":1535369537,
29+
"component":"server"
30+
}
31+
```
32+
33+
#### Shutdown
34+
35+
```json
36+
{
37+
"protocol":"choria:lifecycle:shutdown:1",
38+
"identity":"c1.example.net",
39+
"component":"server",
40+
"timestamp":1535369536
41+
}
42+
```
43+
44+
## Viewing events
45+
46+
In a shell configured as a Choria Client run `choria tool event` to view events in real time.
47+
48+
These events do not traverse Federation borders, so you have to view them in the network you care to observe. You can though configure a Choria Adapter to receive them and adapt them onto a NATS Stream from where you can replicate them to other data centers.
49+
50+
## Emitting an event
51+
52+
```go
53+
event, err := lifecycle.New(lifecycle.Startup, lifecycle.Identity("my.identity"), lifecycle.Component("my_app"), lifecycle.Version("0.0.1"))
54+
panicIfErr(err)
55+
56+
// conn is a Choria connector
57+
err = lifecycle.PublishEvent(event, conn)
58+
```
59+
60+
If you are emitting `lifecycle.Shutdown` events right before exiting be sure to call `conn.Close()` so the buffers are flushed prior to shutdown.
61+
62+
## Receiving a events
63+
64+
These events are used to orchestrate associated tools like the [Provisioning Server](https://github.com/choria-io/provisioning-agent) that listens for these events and immediately add a new node to the provisioning queue.
65+
66+
To receive `startup` events for the `server`:
67+
68+
```go
69+
events := make(chan *choria.ConnectorMessage, 1000)
70+
71+
// conn is a choria framework connector
72+
// fw is the choria framework
73+
err = conn.QueueSubscribe(ctx, fw.NewRequestID(), "choria.lifecycle.event.startup.server", "", events)
74+
panicIfError(err)
75+
76+
for {
77+
select {
78+
case e := <-events:
79+
event, err := lifecycle.NewFromJSON(e.Data)
80+
if err != nil {
81+
continue
82+
}
83+
84+
fmt.Printf("Received a startup from %s", event.Identity())
85+
case <-ctx.Done():
86+
return
87+
}
88+
}
89+
```

0 commit comments

Comments
 (0)