Documentation ¶
Index ¶
- type Broker
- type Client
- type DefaultClient
- func (c *DefaultClient) Channel() chan Message
- func (c *DefaultClient) Discard()
- func (c *DefaultClient) Get(key string) any
- func (c *DefaultClient) HasSubscription(sub string) bool
- func (c *DefaultClient) Id() string
- func (c *DefaultClient) IsDiscarded() bool
- func (c *DefaultClient) Send(m Message)
- func (c *DefaultClient) Set(key string, value any)
- func (c *DefaultClient) Subscribe(subs ...string)
- func (c *DefaultClient) Subscriptions(prefixes ...string) map[string]SubscriptionOptions
- func (c *DefaultClient) Unset(key string)
- func (c *DefaultClient) Unsubscribe(subs ...string)
- type Message
- type SubscriptionOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Broker ¶
type Broker struct {
// contains filtered or unexported fields
}
Broker defines a struct for managing subscriptions clients.
func (*Broker) ClientById ¶
ClientById finds a registered client by its id.
Returns non-nil error when client with clientId is not registered.
func (*Broker) Clients ¶
Clients returns a shallow copy of all registered clients indexed with their connection id.
func (*Broker) Unregister ¶
Unregister removes a single client by its id.
If client with clientId doesn't exist, this method does nothing.
type Client ¶
type Client interface { // Id Returns the unique id of the client. Id() string // Channel returns the client's communication channel. Channel() chan Message // Subscriptions returns a shallow copy of the client subscriptions matching the prefixes. // If no prefix is specified, returns all subscriptions. Subscriptions(prefixes ...string) map[string]SubscriptionOptions // Subscribe subscribes the client to the provided subscriptions list. // // Each subscription can also have "options" (json serialized SubscriptionOptions) as query parameter. // // Example: // // Subscribe( // "subscriptionA", // `subscriptionB?options={"query":{"a":1},"headers":{"x_token":"abc"}}`, // ) Subscribe(subs ...string) // Unsubscribe unsubscribes the client from the provided subscriptions list. Unsubscribe(subs ...string) // HasSubscription checks if the client is subscribed to `sub`. HasSubscription(sub string) bool // Set stores any value to the client's context. Set(key string, value any) // Unset removes a single value from the client's context. Unset(key string) // Get retrieves the key value from the client's context. Get(key string) any // Discard marks the client as "discarded", meaning that it // shouldn't be used anymore for sending new messages. // // It is safe to call Discard() multiple times. Discard() // IsDiscarded indicates whether the client has been "discarded" // and should no longer be used. IsDiscarded() bool // Send sends the specified message to the client's channel (if not discarded). Send(m Message) }
Client is an interface for a generic subscription client.
type DefaultClient ¶
type DefaultClient struct {
// contains filtered or unexported fields
}
DefaultClient defines a generic subscription client.
func NewDefaultClient ¶
func NewDefaultClient() *DefaultClient
NewDefaultClient creates and returns a new DefaultClient instance.
func (*DefaultClient) Channel ¶
func (c *DefaultClient) Channel() chan Message
Channel implements the [Client.Channel] interface method.
func (*DefaultClient) Discard ¶
func (c *DefaultClient) Discard()
Discard implements the [Client.Discard] interface method.
func (*DefaultClient) Get ¶
func (c *DefaultClient) Get(key string) any
Get implements the [Client.Get] interface method.
func (*DefaultClient) HasSubscription ¶
func (c *DefaultClient) HasSubscription(sub string) bool
HasSubscription implements the [Client.HasSubscription] interface method.
func (*DefaultClient) Id ¶
func (c *DefaultClient) Id() string
Id implements the [Client.Id] interface method.
func (*DefaultClient) IsDiscarded ¶
func (c *DefaultClient) IsDiscarded() bool
IsDiscarded implements the [Client.IsDiscarded] interface method.
func (*DefaultClient) Send ¶
func (c *DefaultClient) Send(m Message)
Send sends the specified message to the client's channel (if not discarded).
func (*DefaultClient) Set ¶
func (c *DefaultClient) Set(key string, value any)
Set implements the [Client.Set] interface method.
func (*DefaultClient) Subscribe ¶
func (c *DefaultClient) Subscribe(subs ...string)
Subscribe implements the [Client.Subscribe] interface method.
Empty subscriptions (aka. "") are ignored.
func (*DefaultClient) Subscriptions ¶
func (c *DefaultClient) Subscriptions(prefixes ...string) map[string]SubscriptionOptions
Subscriptions implements the [Client.Subscriptions] interface method.
It returns a shallow copy of the client subscriptions matching the prefixes. If no prefix is specified, returns all subscriptions.
func (*DefaultClient) Unset ¶
func (c *DefaultClient) Unset(key string)
Unset implements the [Client.Unset] interface method.
func (*DefaultClient) Unsubscribe ¶
func (c *DefaultClient) Unsubscribe(subs ...string)
Unsubscribe implements the [Client.Unsubscribe] interface method.
If subs is not set, this method removes all registered client's subscriptions.