Documentation ¶
Index ¶
- Variables
- type NATSProvider
- func (p *NATSProvider) Close()
- func (p *NATSProvider) Flush() error
- func (p *NATSProvider) Open() (err error)
- func (p *NATSProvider) Publish(subject string, msg []byte) error
- func (p *NATSProvider) Request(subject string, msg []byte) (*nats.Msg, error)
- func (p *NATSProvider) Subscribe(subject string, callback func(*nats.Msg)) error
- func (p *NATSProvider) Unsubscribe(subject string) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrAlreadySubscribed is an error firing when caller tries to subscribe to the same subject they are already subscribed ErrAlreadySubscribed = errors.New("only one subscription per subject supported") )
Functions ¶
This section is empty.
Types ¶
type NATSProvider ¶
type NATSProvider struct {
// contains filtered or unexported fields
}
NATSProvider is a struct representing NATS communications.
func New ¶
func New(connectionURLs []string) *NATSProvider
New is the constructor for NATSProvider. connectionURLs - addresses of NATS cluster. logger - logger to log error events into.
func (*NATSProvider) Close ¶
func (p *NATSProvider) Close()
Close closes the connection with NATS server/cluster.
func (*NATSProvider) Flush ¶
func (p *NATSProvider) Flush() error
func (*NATSProvider) Open ¶
func (p *NATSProvider) Open() (err error)
Open connects to NATS cluster by addresses provided in constructor.
func (*NATSProvider) Publish ¶
func (p *NATSProvider) Publish(subject string, msg []byte) error
Publish publishes a message with contents in msg into the provided subject.
func (*NATSProvider) Request ¶
func (p *NATSProvider) Request(subject string, msg []byte) (*nats.Msg, error)
func (*NATSProvider) Subscribe ¶
func (p *NATSProvider) Subscribe(subject string, callback func(*nats.Msg)) error
Subscribe creates a subscription to specified subject with the provided callback. Only one subscruption per subject supported, to change the subscription unsubscribe first. Attempting to subscribe for the same subject will return ErrAlreadySubscribed, the subscription stays unchanged.
func (*NATSProvider) Unsubscribe ¶
func (p *NATSProvider) Unsubscribe(subject string) error
Unsubscribe unsubscribes from the provided subject. If no subscription exists for the subject, it's a no-op.