diff --git a/_examples/http-to-kafka/main.go b/_examples/http-to-kafka/main.go index 4cf96a440..9eb3a6cfa 100644 --- a/_examples/http-to-kafka/main.go +++ b/_examples/http-to-kafka/main.go @@ -76,7 +76,7 @@ func main() { return nil, errors.New("empty object kind") } - // just forward from http subscribert to kafka publisher + // just forward from http subscriber to kafka publisher return []*message.Message{msg}, nil }, ) @@ -85,8 +85,9 @@ func main() { } go func() { + // HTTP server needs to be started after router is ready. <-r.Running() - httpSubscriber.RunHTTPServer() + httpSubscriber.StartHTTPServer() }() r.Run() diff --git a/message/infrastructure/http/subscriber.go b/message/infrastructure/http/subscriber.go index 1943cd035..fe74ff5fa 100644 --- a/message/infrastructure/http/subscriber.go +++ b/message/infrastructure/http/subscriber.go @@ -80,7 +80,9 @@ func (s *Subscriber) Subscribe(topic string) (chan *message.Message, error) { return messages, nil } -func (s *Subscriber) RunHTTPServer() error { +// StartHTTPServer starts http server. +// StartHTTPServer must be called after all subscribe function are called. +func (s *Subscriber) StartHTTPServer() error { return s.server.ListenAndServe() }