-
Notifications
You must be signed in to change notification settings - Fork 262
Conversation
…e#382) Signed-off-by: David Chung <david.chung@docker.com>
Signed-off-by: David Chung <david.chung@docker.com>
Signed-off-by: David Chung <david.chung@docker.com>
Signed-off-by: David Chung <david.chung@docker.com>
Signed-off-by: David Chung <david.chung@docker.com>
Signed-off-by: David Chung <david.chung@docker.com>
…mentations Signed-off-by: David Chung <david.chung@docker.com>
Please sign your commits following these rules: $ git clone -b "group2-fsm" git@github.com:chungers/infrakit.git somewhere
$ cd somewhere
$ git rebase -i HEAD~842354411592
editor opens
change each 'pick' to 'edit'
save the file and quit
$ git commit --amend -s --no-edit
$ git rebase --continue # and repeat the amend for each commit
$ git push -f Amending updates the existing PR. You DO NOT need to open a new one. |
Signed-off-by: David Chung <david.chung@docker.com>
Signed-off-by: David Chung <david.chung@docker.com>
Signed-off-by: David Chung <david.chung@docker.com>
Signed-off-by: David Chung <david.chung@docker.com>
Signed-off-by: David Chung <david.chung@docker.com>
Signed-off-by: David Chung <david.chung@docker.com>
pkg/broker/server/sse.go
Outdated
@@ -140,6 +162,9 @@ func (b *Broker) ServeHTTP(rw http.ResponseWriter, req *http.Request) { | |||
func (b *Broker) run() { | |||
for { | |||
select { | |||
case <-b.finish: | |||
log.Infoln("Broker finished") | |||
return | |||
|
|||
case subscription := <-b.newClients: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tested this PR with the code below.
func main() {
client, _ := rpc.NewClient("/root/.infrakit/plugins/event")
topics, _ := client.Topics()
fmt.Printf("%v \n", topics)
sub, _ := client.(spi.Subscriber)
typed, err := sub.SubscribeOn(spi.NewTopic("timer/sec/1"))
if err != nil {
fmt.Errorf("%v \n", err)
}
for {
select {
case ret := <-typed:
fmt.Printf("%v \n", ret)
}
}
}
Then I found a problem that only one client can subscribe in one topic.
When a new client starts subscribing to a topic that another client already subscribes to, the old client will not receive any messages.
The cause of this problem is thought to be because Broker uses radix's insert, so if you try to add a new client with the same topic, old client will be overwritten.
Is this a specification?
If so, the old client's session should be closed. If not, we need to fix.
Perhaps it would be better to discuss this separately from this PR. In that case open a new issue and consider a patch.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I will fix this before merging it in. Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed this and a test case now has two clients subscribing to the same topic.
examples/event/time/main.go
Outdated
Short: "Timer event plugin", | ||
} | ||
|
||
name := cmd.Flags().String("name", "time", "Plugin name to advertise for discovery") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a trivial thing, I think that it is better to name it event-time
in order to keep it in balance with other examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. Thanks!
Signed-off-by: David Chung <david.chung@docker.com>
Signed-off-by: David Chung <david.chung@docker.com>
…in events Signed-off-by: David Chung <david.chung@docker.com>
This PR we introduce:
Features
compute/instance/create
orcompute/instance/unhealthy
. Subscribers can subscribe to topics at exactly matching path (e.g.compute/instance/unhealthy
) or at coarser granularity (e.g.compute/instance
) to receive events from the sub-topics.New CLI / Binary
A new subcommand
event
has been added. The syntax is the same asinfrakit metadata
. You canls
ortail
:ls
lists all the event topics from all the plugins that export the Event interface.tail
followed by a path will let you watch the event stream in real-time.A new binary in
examples/event/time
demonstrates how to incorporate the Event SPI into your plugin implementation. The example implementsRunning Examples
examples/event/time
plugin:~/projects/src/github.com/docker/infrakit$ build/infrakit-event-time INFO[0000] Timer starting publish on channel: 0xc420019020 INFO[0000] Listening at: /Users/davidchung/.infrakit/plugins/event-time INFO[0000] PID file at /Users/davidchung/.infrakit/plugins/event-time.pid
Now run the commands below in another console:
The presentation can be customized by the
--url
flag where template url can be used, or usestr://
scheme for the url to inline template text: