Documentation ¶
Overview ¶
Package kiara provides a thin pubsub wrapper that allows Go applications to communicate easily.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // This error is reported through PubSub.Errors() when a channel through which messages are sent is full. ErrSlowConsumer = errors.New("consumer is too slow; message discarded") // This error is returned when a given context is cancelled. ErrCancelled = errors.New("cancelled") // This error is returned when the second argument of PubSub.Subscribe() is not a channel or the direction of the channel is not <-. ErrArgumentMustBeChannel = errors.New("argument must be a channel") )
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option configures PubSub.
func DeliveredChannelSize ¶ added in v0.2.0
DeliveredChannelSize sets the size of a channel that contains messages that are sent by the backend and about to be delivered.
func ErrorChannelSize ¶
ErrorChannelSize sets a size of a channel through which async errors are reported.
func PublishChannelSize ¶ added in v0.2.0
PublishChannelSize sets the size of a channel that contains messages that will be sent later.
type PubSub ¶
type PubSub struct {
// contains filtered or unexported fields
}
PubSub provides a way to send and receive arbitrary data.
func (*PubSub) Close ¶
func (p *PubSub) Close()
Close stops the PubSub and releases its resources. It also stop its underlying adapter so we don't need stopping adapters manually.
func (*PubSub) Errors ¶
Errors returns a channel through which asynchronous errors are reported. When the channel is full, subsequent errors are discarded.
func (*PubSub) Publish ¶
Publish publishes `data` to the underlying message broker. This means `data` is sent to every channels that is `Subscribe`ing the same topic as the given one. It returns an error when it cannot prepare publishing due to marshaling error or being cancelled by `ctx`. Any other errors are reported asynchronously via PubSub.Errors().
func (*PubSub) Subscribe ¶
func (p *PubSub) Subscribe(topic string, channel interface{}) (*Subscription, error)
Subscribe binds a channel to the given topic. This means any messages that are `Publish`ed toghther with the same topic are sent to the given channel.
A `channel` must be the type of `chan T` or `chan<- T` where `T` is any type that can be `Unmarshal`ed by the codec of the `PubSub`.
Note that PubSub internally passes *T to its internal codec when T is not a pointer. In most cases you don't have to care about it but it may be confusing when the ccodec assumes that the data implements certain interfaces.
It's ok to subscribe to one topic more than one times. In this case, messages are broadcasted to all channels that are subscribing to the topic.
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
Subscription binds a channel to specific topic.
func (*Subscription) Unsubscribe ¶
func (s *Subscription) Unsubscribe() error
Unsubscribe removes a binding from corresponding channel to its associated topic. Once `Unsubscribe` is returned, it is guaranteed that no more messages are sent to the channel.
Directories ¶
Path | Synopsis |
---|---|
adapter
|
|
inmemory
Package inmemory provides a simple pubsub adapter mainly aimed at testing.
|
Package inmemory provides a simple pubsub adapter mainly aimed at testing. |
nats
Package nats provides a NATS adapter for Kiara.
|
Package nats provides a NATS adapter for Kiara. |
redis
Package redis provides a Redis adapter for Kiara.
|
Package redis provides a Redis adapter for Kiara. |
codec
|
|
gob
Package gob provides a Codec for gob.
|
Package gob provides a Codec for gob. |
json
Package msgpack provides a Codec for JSON
|
Package msgpack provides a Codec for JSON |
msgpack
Package msgpack provides a Codec for MessagePack
|
Package msgpack provides a Codec for MessagePack |
proto
Package msgpack provides a Codec for Protocol Buffers
|
Package msgpack provides a Codec for Protocol Buffers |
examples
|
|
Package types provides types and interfaces that are needed to implement backend adapters.
|
Package types provides types and interfaces that are needed to implement backend adapters. |