Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrSubscriptionNotFound = errors.New("pubsub: subscription not found")
Functions ¶
This section is empty.
Types ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server should be created via pubsub.NewServer fuction
Example ¶
s := NewServer() topic := "topic" subscriber := "sub" msg := []byte(`{"foo":"bar"}`) s.Subscribe(topic, subscriber) s.Publish(topic, msg) msg, err := s.Poll(topic, subscriber) if err != nil { log.Fatalf("Unexpected error: %v", err) } s.Unsubscribe(topic, subscriber) fmt.Println(string(msg))
Output: {"foo":"bar"}
func NewServer ¶
func NewServer() *Server
NewServer initialize pubsub server. Please create Server only via NewServer
func (*Server) Poll ¶
Poll - returns next message on topic of subscriber and removes it from subscribers queue. If there are no new messages it will return nil, nil. If there is no subscription it will return pubsub.ErrSubscriptionNotFound
func (*Server) Publish ¶
Publish - deliver msg to all topic subscribers This function traverse all topic subscribers, so it is better to call it in async manner: go s.Publish(topic, msg)
func (*Server) Subscribe ¶
Subscribe - subscribes subscriber to topic. Subscriber can receive messages received after subscription on this topic with Poll
func (*Server) Unsubscribe ¶
Unsubscribe - remove topic's subscription for client