Documentation ¶
Index ¶
- Variables
- func Addr(addr string) nats.Option
- func ReplyServer(msg *protos.ReplyMessage) error
- func UserInfo(user, password string) nats.Option
- func With(options nats.Options) nats.Option
- type StackExchange
- func (exc *StackExchange) Ask(ctx context.Context, msg wolfsocket.Message, token string) (response wolfsocket.Message, err error)
- func (exc *StackExchange) AskServer(ctx context.Context, channel string, msg protos.ServerMessage) (response *protos.ReplyMessage, err error)
- func (exc *StackExchange) NotifyAsk(msg wolfsocket.Message, token string) error
- func (exc *StackExchange) OnConnect(c *wolfsocket.Conn) error
- func (exc *StackExchange) OnDisconnect(c *wolfsocket.Conn)
- func (exc *StackExchange) Publish(channel string, msgs []protos.ServerMessage) error
- func (exc *StackExchange) Reply(err error, token string) error
- func (exc *StackExchange) Subscribe(c *wolfsocket.Conn, channel string)
- func (exc *StackExchange) Unsubscribe(c *wolfsocket.Conn, channel string)
- type StackExchangeCfgs
Constants ¶
This section is empty.
Variables ¶
var ( ErrChannelEmpty = errors.New("We do not accept messages with empty channel") // InvalidPrefix is returned when a message with a channel prefix // that does not match the expected prefix is received during subscription. // The message is not executed to prevent unauthorized access or incorrect behavior. InvalidPrefix = errors.New("message received with invalid prefix") )
Functions ¶
func ReplyServer ¶ added in v0.1.14
func ReplyServer(msg *protos.ReplyMessage) error
func With ¶
func With(options nats.Options) nats.Option
With accepts a nats.Options structure which contains the whole configuration and returns a nats.Option which can be passed to the `NewStackExchange`'s second input variadic argument. Note that use this method only when you want to override the default options at once.
Types ¶
type StackExchange ¶
type StackExchange struct { // If you use the same nats server instance for multiple wolfsocket apps, // set this to different values across your apps. SubjectPrefix string // contains filtered or unexported fields }
StackExchange is a `wolfsocket.StackExchange` for nats based on https://nats-io.github.io/docs/developer/tutorials/pubsub.html.
func NewStackExchange ¶
func NewStackExchange(cfg StackExchangeCfgs, options ...nats.Option) (*StackExchange, error)
NewStackExchange returns a new nats StackExchange. The required field is "url" which should be in the form of nats connection string, e.g. nats://username:pass@localhost:4222. Other option is to leave the url with localhost:4222 and pass authentication options such as `nats.UserInfo(username, pass)` or nats.UserCredentials("./userCredsFile") at the second variadic input argument.
Options can be used to register nats error and close handlers too.
Alternatively, use the `With(nats.Options)` function to customize the client through struct fields.
func (*StackExchange) Ask ¶
func (exc *StackExchange) Ask(ctx context.Context, msg wolfsocket.Message, token string) (response wolfsocket.Message, err error)
Ask implements server Ask for nats. It blocks.
func (*StackExchange) AskServer ¶ added in v0.1.14
func (exc *StackExchange) AskServer(ctx context.Context, channel string, msg protos.ServerMessage) (response *protos.ReplyMessage, err error)
func (*StackExchange) NotifyAsk ¶
func (exc *StackExchange) NotifyAsk(msg wolfsocket.Message, token string) error
NotifyAsk notifies and unblocks a "msg" subscriber, called on a server connection's read when expects a result.
func (*StackExchange) OnConnect ¶
func (exc *StackExchange) OnConnect(c *wolfsocket.Conn) error
OnConnect prepares the connection nats subscriber and subscribes to itself for direct wolfsocket messages. It's called automatically after the wolfsocket server's OnConnect (if any) on incoming client connections.
func (*StackExchange) OnDisconnect ¶
func (exc *StackExchange) OnDisconnect(c *wolfsocket.Conn)
OnDisconnect terminates the connection's subscriber that created on the `OnConnect` method. It unsubscribes to all opened channels and closes the internal read messages channel. It's called automatically when a connection goes offline, manually by server or client or by network failure.
func (*StackExchange) Publish ¶
func (exc *StackExchange) Publish(channel string, msgs []protos.ServerMessage) error
func (*StackExchange) Reply ¶ added in v0.1.14
func (exc *StackExchange) Reply(err error, token string) error
reply ask message
func (*StackExchange) Subscribe ¶
func (exc *StackExchange) Subscribe(c *wolfsocket.Conn, channel string)
Subscribe subscribes to a specific channel, it's called automatically on wolfsocket namespace connected.
func (*StackExchange) Unsubscribe ¶
func (exc *StackExchange) Unsubscribe(c *wolfsocket.Conn, channel string)
Unsubscribe unsubscribes from a specific channel, it's called automatically on wolfsocket namespace disconnect.
type StackExchangeCfgs ¶ added in v0.1.14
type StackExchangeCfgs struct { SubjectPrefix string wolfsocket.Namespaces *wolfsocket.Server }