resurrect broker event (#26)

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2020-08-27 11:18:02 +03:00
committed by GitHub
parent 36c53b4917
commit b4ccde2228
6 changed files with 56 additions and 23 deletions

View File

@@ -25,6 +25,11 @@ type tunSubscriber struct {
listener tunnel.Listener
}
type tunEvent struct {
topic string
message *broker.Message
}
// used to access tunnel from options context
type tunnelKey struct{}
type tunnelAddr struct{}
@@ -123,9 +128,12 @@ func (t *tunSubscriber) run() {
c.Close()
// handle the message
go t.handler(&broker.Message{
Header: m.Header,
Body: m.Body,
go t.handler(&tunEvent{
topic: t.topic,
message: &broker.Message{
Header: m.Header,
Body: m.Body,
},
})
}
}
@@ -148,6 +156,22 @@ func (t *tunSubscriber) Unsubscribe() error {
}
}
func (t *tunEvent) Topic() string {
return t.topic
}
func (t *tunEvent) Message() *broker.Message {
return t.message
}
func (t *tunEvent) Ack() error {
return nil
}
func (t *tunEvent) Error() error {
return nil
}
func NewBroker(opts ...broker.Option) (broker.Broker, error) {
options := broker.Options{
Context: context.Background(),