PubSubMiddleware Synchronize notification to peer node middleware
(router IRoutes, pubSub *p2p.PubSub)
| 33 | |
| 34 | // PubSubMiddleware Synchronize notification to peer node middleware |
| 35 | func PubSubMiddleware(router IRoutes, pubSub *p2p.PubSub) HandlerFunc { |
| 36 | subscribe(router, pubSub) |
| 37 | return func(context *Context) error { |
| 38 | // sync write operate cmd and remove 'publish' command |
| 39 | if context.Op.IsMasterOnly() && strings.ToUpper(context.Cmd) != "PUBLISH" { |
| 40 | args := make([]string, len(context.Args)) |
| 41 | for k, v := range context.Args { |
| 42 | args[k] = string(v.([]byte)) |
| 43 | } |
| 44 | s, _ := json.Marshal(args) |
| 45 | pubSub.Outbound <- string(s) |
| 46 | logrus.Info("outbound: ", string(s)) |
| 47 | } |
| 48 | return context.Next() |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | func subscribe(router IRoutes, pubSub *p2p.PubSub) { |
| 53 | utils.GoWithRecover(func() { |
no test coverage detected