events
events/event.go
Create NSQ helpers. Create an NSQPublisher helper that will allow us to publish events in the system in a consistent way. It basically just uses our dictated Event type, to make sure everything's using the same format. Create an NSQSubscriber helper that will allow us to listen for events in the system. It basically creates an nsq.Consumer, adds a handler to it, connects it to lookupds, and has a helper to block until the consumer is told to stop. Eventually, if github.com/bitly/nsq/issues/601 goes well, we should also have this poll our DNS to check for new nsqlookupds, and automatically connect to them.
| paddy@0 | 1 package events |
| paddy@0 | 2 |
| paddy@0 | 3 import ( |
| paddy@0 | 4 "time" |
| paddy@0 | 5 ) |
| paddy@0 | 6 |
| paddy@1 | 7 const ( |
| paddy@1 | 8 ActionCreated = "created" |
| paddy@1 | 9 ActionUpdated = "updated" |
| paddy@1 | 10 ActionDeleted = "deleted" |
| paddy@1 | 11 ) |
| paddy@1 | 12 |
| paddy@0 | 13 type Event struct { |
| paddy@0 | 14 System string `json:"system"` |
| paddy@0 | 15 Model string `json:"model"` |
| paddy@0 | 16 ID string `json:"id"` |
| paddy@0 | 17 Action string `json:"action"` |
| paddy@0 | 18 Timestamp time.Time `json:"timestamp"` |
| paddy@1 | 19 Data interface{} `json:"data,omitempty"` |
| paddy@0 | 20 } |