Documentation ¶
Overview ¶
Package subscribe is a helper that interacts with Pub/Sub Cloud feature. It stores active websockets. When message is received, it notifies the concerned websocket if any.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewSubscriber ¶
func NewSubscriber(opt SubscriberOptions) (*subscriberImpl, error)
NewSubscriber builds a new Pub/Sub subscriber. It retrieve the subscription using the project ID and a subscription ID. The websocket store is initialized. The logger is created using the base logger configuration.
Types ¶
type JobBody ¶
JobBody is the format of the job output retrieved from the Pub/Sub message Example: { "message": "job is still in progress", "progress": 35 }
type JobStatus ¶
type JobStatus struct { // The job output Body JobBody `json:"body"` // The code attribute of the Pub/Sub message Code int `json:"code"` // The status attribute of the Pub/Sub message Status string `json:"status"` // The ordering key of the Pub/Sub message OrderingKey string `json:"ordering_key"` }
JobStatus holds the jobStatus and the JobBody
type Subscriber ¶
type Subscriber interface { // Close uses the cancel callback to stop receiving new messages from the // subscription. Close() // Listen uses sub.Receive to receive new messages from the subscription. // When a message is received, the configured callback is called. Listen() error // NewJobStatus converts a received Pub/Sub message into a jobBody. // It reads the message attributes to retrieve a code, a status and the ordering // key. It also parses the message data as JSON into a jobStatus entry. NewJobStatus(pMsg *pubsub.Message) (*JobStatus, error) }
Subscriber interacts with Pub/Sub through a subscription. It holds the receive callback context and its cancel callback. It also has its own logger.