Register - Registers a remote handler to this event bus for a remote subscribe - a given client address only needs to subscribe once event will be republished in local event bus
(arg *SubscribeArg, success *bool)
| 130 | // for a remote subscribe - a given client address only needs to subscribe once |
| 131 | // event will be republished in local event bus |
| 132 | func (service *ServerService) Register(arg *SubscribeArg, success *bool) error { |
| 133 | subscribers := service.server.subscribers |
| 134 | if !service.server.HasClientSubscribed(arg) { |
| 135 | rpcCallback := service.server.rpcCallback(arg) |
| 136 | switch arg.SubscribeType { |
| 137 | case Subscribe: |
| 138 | service.server.eventBus.Subscribe(arg.Topic, rpcCallback) |
| 139 | case SubscribeOnce: |
| 140 | service.server.eventBus.SubscribeOnce(arg.Topic, rpcCallback) |
| 141 | } |
| 142 | var topicSubscribers []*SubscribeArg |
| 143 | if _, ok := subscribers[arg.Topic]; ok { |
| 144 | topicSubscribers = []*SubscribeArg{arg} |
| 145 | } else { |
| 146 | topicSubscribers = subscribers[arg.Topic] |
| 147 | topicSubscribers = append(topicSubscribers, arg) |
| 148 | } |
| 149 | subscribers[arg.Topic] = topicSubscribers |
| 150 | } |
| 151 | *success = true |
| 152 | return nil |
| 153 | } |