Documentation ¶
Index ¶
- type Config
- type PubSub
- func (p *PubSub) Close() error
- func (p *PubSub) IsConnected() bool
- func (p *PubSub) Publish(topic string, messages ...*message.Message) error
- func (p *PubSub) PublishWithOpts(topic string, msg *message.Message, _ ...spi.Option) error
- func (p *PubSub) Subscribe(ctx context.Context, topic string) (<-chan *message.Message, error)
- func (p *PubSub) SubscribeWithOpts(_ context.Context, topic string, _ ...spi.Option) (<-chan *message.Message, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // Timeout is the time that we should wait for an Ack or a Nack. Timeout time.Duration // Concurrency specifies the maximum number of concurrent requests. Concurrency int // BufferSize is the size of the Go channel buffer for a subscription. BufferSize int }
Config holds the configuration for the publisher/subscriber.
type PubSub ¶
PubSub implements a publisher/subscriber using Go channels. This implementation works only on a single node, i.e. handlers are not distributed. In order to distribute the load across a cluster, a persistent message queue (such as RabbitMQ or Kafka) should instead be used.
func (*PubSub) IsConnected ¶
IsConnected return true is connected.
func (*PubSub) Publish ¶
Publish publishes the given messages to the given topic. This function returns immediately after sending the messages to the Go channel(s), although it will block if the concurrency limit (defined by Config.Concurrency) has been reached.
func (*PubSub) PublishWithOpts ¶
PublishWithOpts simply calls Publish since options are not supported.
func (*PubSub) Subscribe ¶
Subscribe subscribes to a topic and returns the Go channel over which messages are sent. The returned channel will be closed when Close() is called on this struct.
func (*PubSub) SubscribeWithOpts ¶
func (p *PubSub) SubscribeWithOpts(_ context.Context, topic string, _ ...spi.Option) (<-chan *message.Message, error)
SubscribeWithOpts subscribes to a topic and returns the Go channel over which messages are sent. The returned channel will be closed when Close() is called on this struct.