Implement Cross-Process Events
masterEventBus supports cross-process communication using a client-server model via RPC services.
- Server Service: Listens to client subscriptions and can publish events.
- Client Service: Listens to remotely published events from a server.
Server Implementation Example:
func main() {
server := NewServer(":2010", "/_server_bus_", New())
server.Start()
server.EventBus().Publish("main:calculator", 4, 6)
server.Stop()
}Client Implementation Example:
func main() {
client := NewClient(":2015", "/_client_bus_", New())
client.Start()
// Subscribe to events from the server at :2010 on the /_server_bus_ path
client.Subscribe("main:calculator", calculator, ":2010", "/_server_bus_")
client.Stop()
}