Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ConditionFactories = map[string]func() Condition{ new(KeyEqualCondition).GetName(): func() Condition { return new(KeyEqualCondition) }, new(MetadataKeyEqualCondition).GetName(): func() Condition { return new(MetadataKeyEqualCondition) }, }
ConditionFactories is where you can add custom conditions
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client will subscribe to the upstream hub over the provided grpc conn.
func NewClient ¶
func NewClient(namespace []string, conditions []byte, conn *grpc.ClientConn) *Client
NewClient returns a new initialized client which connect to hub server, for Pub Sub Mechanism.
func (*Client) PublishList ¶
PublishList publishes received message over the sender channel to the hub server until the ctx is cancelled/done or msgSender is closed.
func (*Client) Subscribe ¶
Subscribe the given Client to upstream hub for receiving published messages. The channel on which message would be received should have enough buffer to hold for fast sender hub. It's a blocking API.
func (*Client) UnSubscribe ¶
func (c *Client) UnSubscribe()
UnSubscribe the current client from the upstream hub.
type Condition ¶
type Condition interface { // GetName returns the condition's name. GetName() string // Fulfills returns true if the request is fulfilled by the condition. Fulfills(request *Request) bool }
Condition either do or do not fulfill a subscription request.
type Conditions ¶
Conditions is a collection of conditions.
func (Conditions) Fulfills ¶
func (cs Conditions) Fulfills(request *Request) bool
Fulfills returns true if all condition are fulfilled.
func (Conditions) MarshalJSON ¶
func (cs Conditions) MarshalJSON() ([]byte, error)
MarshalJSON marshals a list of conditions to json.
func (Conditions) UnmarshalJSON ¶
func (cs Conditions) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshal a list of conditions from json.
type DurationKind ¶
type DurationKind int
DurationKind represents what kind of duration has been sent.
const ( // Broadcast duration Broadcast DurationKind = iota // Stream duration is overall stream duration Stream )
type HookMetadata ¶
type HookMetadata struct { DurationKind // if this was error Err error }
HookMetadata contains some embedded information for the hook.
type Hooker ¶
type Hooker interface { PubHook(msg *hub.KV) SubHook(ops SubscriberOPS) Duration(metadata HookMetadata, d time.Duration) }
Hooker implementation provides hook methods that gets called during the pub and sub operations.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub provides gRPC implementation of Publish/Subscribe messaging paradigm.
type KeyEqualCondition ¶
type KeyEqualCondition struct {
Equals string `json:"equals"`
}
KeyEqualCondition is a subscription condition, that will only match when the provided key is equal to Equals.
func (*KeyEqualCondition) Fulfills ¶
func (c *KeyEqualCondition) Fulfills(request *Request) bool
Fulfills returns true if the given key is same as in KeyEqualCondition.Equals
func (*KeyEqualCondition) GetName ¶
func (c *KeyEqualCondition) GetName() string
GetName returns the condition's name.
type MetadataKeyEqualCondition ¶
type MetadataKeyEqualCondition struct { Equals string `json:"equals"` KeyName string `json:"key_name"` }
MetadataKeyEqualCondition is a subscription condition, which only match when the provided metadata key equals to the Equals
func (*MetadataKeyEqualCondition) Fulfills ¶
func (c *MetadataKeyEqualCondition) Fulfills(request *Request) bool
Fulfills returns true if the given MetadataKeyEqualCondition.KeyName value is same as in MetadataKeyEqualCondition.Equals
func (*MetadataKeyEqualCondition) GetName ¶
func (c *MetadataKeyEqualCondition) GetName() string
GetName returns the condition's name.
type NoopHook ¶
type NoopHook struct { }
NoopHook implements Hooker interface and does nothing.
func (NoopHook) SubHook ¶
func (n NoopHook) SubHook(ops SubscriberOPS)
type Options ¶
type Options func(*Hub)
Options Configure the Hub with different parameters.
func WithHooker ¶
WithHooker configures the hub to use the passed Hooker implementation.
func WithPublisherTimeout ¶
WithPublisherTimeout configures the hub with timeout duration that hub respect before timing out the publishing at server.
func WithSubscriberBufferCount ¶
WithSubscriberBufferCount configures the hub with the count which is then used to create a buffer channel for each subscriber that connect with hub server.
type Request ¶
type Request struct { Key string `json:"key"` // Metadata is the request's propagated Metadata. Metadata KVMetadata `json:"metadata"` }
Request is the Condition request object.
type SubscriberOPS ¶
type SubscriberOPS int
SubscriberOPS represents what kind of Subscriber Action was performed.
const ( SubscriberCreate SubscriberOPS = 0 SubscriberDelete SubscriberOPS = 1 )