Cluster
gox.Cluster displays read-only information and events of the active distributed adapter.
if gox.Cluster.Enabled() {
log.Printf("Adapter: %s", gox.Cluster.Adapter())
} The distributed operations of sockets, groups and channels use the adapter automatically.
Structure
Cluster
{
Enabled() bool
Adapter() string
When(event string, handler any)
} Methods
| Method | Description |
|---|---|
| Enabled() | Indicates if there is an active adapter. |
| Adapter() | Return the name of the adapter. |
| When() | He records a cluster event handler. |
Enabled()
Firma:func (*ClusterContext) Enabled() bool
It indicates whether the instance uses an active distributed adapter.
clustered := gox.Cluster.Enabled() This result coincides with the distributed state of the current instance, not with the momentary availability of each remote node.
Adapter()
Firma:func (*ClusterContext) Adapter() string
Returns the name of the active adapter.
adapter := gox.Cluster.Adapter() When the cluster is disabled or the runtime is not yet linked, it returns an empty string.
When()
Firma:func (*ClusterContext) When(event string, handler any)
Registers a handler for a distributed runtime event. Currently only supports error.
gox.Cluster.When("error", func(err gox.ClusterError) {
log.Printf("[%s] %s: %s", err.Adapter, err.Operation, err.Error())
}) The required signature is exactly:
func(gox.ClusterError) An event name other than error or a handler with another firm produces panic During the registration. Recording a new handler replaces the previous handler.
See the reference to gox.ClusterError to know their fields, methods and behaviour.
Record the event during the initialization of the application, before starting distributed operations.
Distributed operations
gox.Sockets, gox.Groups and gox.Channels automatically change reach when the adapter is active. The application does not need to publish commands or solve the owner instance.
To know the behavior of these facades, consult gox.Sockets, gox.Groups and gox.Channels.
To learn how to set up the adapter and shared storage, visit Cluster configuration.
Integration with Go
Enabled() and Adapter() They return normal Go values that can be used from Pages, Actions, WebSocket handlers, auxiliary functions and internal application packages.
The handler is run as part of the runtime report; you must quickly complete and delegate slow operations when necessary.
Best practices
- Register the event
errorduring initialization. - Use the exact signature
func(gox.ClusterError). - Avoid blocking the handler with slow operations.
- Do not manually implement the distribution of sockets, groups or channels.