Fix the rest of the code
This commit is contained in:
parent
02aca819d7
commit
536216fd01
@ -33,8 +33,9 @@ func pub() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func sub() {
|
func sub() {
|
||||||
_, err := broker.Subscribe(topic, func(msg *broker.Message) {
|
_, err := broker.Subscribe(topic, func(p broker.Publication) error {
|
||||||
fmt.Println("[sub] received message:", string(msg.Body), "header", msg.Header)
|
fmt.Println("[sub] received message:", string(p.Message().Body), "header", p.Message().Header)
|
||||||
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
@ -155,11 +155,12 @@ func validateSubscriber(sub Subscriber) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *rpcServer) createSubHandler(sb *subscriber, opts options) broker.Handler {
|
func (s *rpcServer) createSubHandler(sb *subscriber, opts options) broker.Handler {
|
||||||
return func(msg *broker.Message) {
|
return func(p broker.Publication) error {
|
||||||
|
msg := p.Message()
|
||||||
ct := msg.Header["Content-Type"]
|
ct := msg.Header["Content-Type"]
|
||||||
cf, err := s.newCodec(ct)
|
cf, err := s.newCodec(ct)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
hdr := make(map[string]string)
|
hdr := make(map[string]string)
|
||||||
@ -190,11 +191,11 @@ func (s *rpcServer) createSubHandler(sb *subscriber, opts options) broker.Handle
|
|||||||
defer co.Close()
|
defer co.Close()
|
||||||
|
|
||||||
if err := co.ReadHeader(&codec.Message{}, codec.Publication); err != nil {
|
if err := co.ReadHeader(&codec.Message{}, codec.Publication); err != nil {
|
||||||
continue
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := co.ReadBody(req.Interface()); err != nil {
|
if err := co.ReadBody(req.Interface()); err != nil {
|
||||||
continue
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fn := func(ctx context.Context, msg Publication) error {
|
fn := func(ctx context.Context, msg Publication) error {
|
||||||
@ -225,6 +226,7 @@ func (s *rpcServer) createSubHandler(sb *subscriber, opts options) broker.Handle
|
|||||||
message: req.Interface(),
|
message: req.Interface(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user