MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / PubSubMiddleware

Function PubSubMiddleware

IceFireDB-PubSub/pkg/router/pubsub.go:35–50  ·  view source on GitHub ↗

PubSubMiddleware Synchronize notification to peer node middleware

(router IRoutes, pubSub *p2p.PubSub)

Source from the content-addressed store, hash-verified

33
34// PubSubMiddleware Synchronize notification to peer node middleware
35func 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
52func subscribe(router IRoutes, pubSub *p2p.PubSub) {
53 utils.GoWithRecover(func() {

Callers 1

NewFunction · 0.92

Calls 3

subscribeFunction · 0.70
IsMasterOnlyMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected