Documentation ¶
Overview ¶
Package azbus provides a simple wrapper for Azure Service Bus.
Index ¶
- Variables
- func GetFromNameRule(name string) *admin.RuleProperties
- func GetToNameRule(name string) *admin.RuleProperties
- func SetLog(l *zap.SugaredLogger)
- func SetReceiveBatchSize(size int)
- type Attributes
- type Manager
- func (m *Manager) CreateQueue(queueName string) (*Queue, error)
- func (m *Manager) CreateSubscription(topicName, subName string) (*Subscription, error)
- func (m *Manager) CreateSubscriptionWithRule(topicName, subName string, rule *admin.RuleProperties) (*Subscription, error)
- func (m *Manager) CreateTopic(topicName string) (*Topic, error)
- func (m *Manager) DeleteQueue(queueName string) error
- func (m *Manager) DeleteSubscription(topicName, subName string) error
- func (m *Manager) DeleteTopic(topicName string) error
- func (m *Manager) SetLockDuration(s string)
- func (m *Manager) SetMaxSizeMB(i int32)
- func (m *Manager) SetMessageTimeToLive(s string)
- func (m *Manager) String() string
- type Message
- type Queue
- func (q *Queue) Abandon(m *Message) error
- func (q *Queue) Close() error
- func (q *Queue) Complete(m *Message) error
- func (q *Queue) GetStatus() (*Status, error)
- func (q *Queue) Receive() ([]*Message, error)
- func (q *Queue) Schedule(data []byte, attrs Attributes, sched time.Time) (int64, error)
- func (q *Queue) Send(data []byte, attrs Attributes) error
- func (q *Queue) String() string
- func (q *Queue) Take(m *Message) error
- type Status
- type Subscription
- func (s *Subscription) Abandon(m *Message) error
- func (s *Subscription) Close() error
- func (s *Subscription) Complete(m *Message) error
- func (s *Subscription) GetStatus() (*Status, error)
- func (s *Subscription) Receive() ([]*Message, error)
- func (s *Subscription) String() string
- func (s *Subscription) Take(m *Message) error
- type Tags
- type Topic
- func (t *Topic) Close() error
- func (t *Topic) GetStatus() (*Status, error)
- func (t *Topic) NewSubscription(subName string) (*Subscription, error)
- func (t *Topic) NewSubscriptionWithPeekLockMode(subName string) (*Subscription, error)
- func (t *Topic) NewSubscriptionWithReceiveAndDeleteMode(subName string) (*Subscription, error)
- func (t *Topic) Schedule(data []byte, attrs Attributes, sched time.Time) (int64, error)
- func (t *Topic) Send(data []byte, attrs Attributes) error
- func (t *Topic) String() string
Constants ¶
This section is empty.
Variables ¶
var ( // ErrQueueNotFound is returned when the queue is not found. ErrQueueNotFound = errors.New("queue not found") // ErrTopicNotFound is returned when the topic is not found. ErrTopicNotFound = errors.New("topic not found") // ErrSubscriptionNotFound is returned when the subscription is not found. ErrSubscriptionNotFound = errors.New("subscription not found") // ErrConflict is returned when the resource already exists. ErrConflict = errors.New("already exists") // ErrInvalidMessage is returned when the message is invalid. ErrInvalidMessage = errors.New("invalid message") // ErrInvalidSequenceNumber is returned when the sequence number is invalid. ErrInvalidSequenceNumber = errors.New("invalid sequence number") // ErrInvalidScheduleTime is returned when the schedule time is invalid. ErrInvalidScheduleTime = errors.New("invalid schedule time") )
Functions ¶
func GetFromNameRule ¶
func GetFromNameRule(name string) *admin.RuleProperties
GetFromNameRule returns a rule that filters messages by the given name.
func GetToNameRule ¶
func GetToNameRule(name string) *admin.RuleProperties
GetToNameRule returns a rule that filters messages by the given name.
func SetReceiveBatchSize ¶ added in v0.0.2
func SetReceiveBatchSize(size int)
SetReceiveBatchSize sets the batch size for receiving messages.
Types ¶
type Attributes ¶
type Attributes map[string]interface{}
Attributes represents the attributes of a message.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager represents a admin client of Azure Service Bus.
func NewManager ¶
NewManager creates a new instance of Manager.
func (*Manager) CreateQueue ¶
CreateQueue creates a Queue with the given name if not exists, and returns the queue instance.
func (*Manager) CreateSubscription ¶
func (m *Manager) CreateSubscription(topicName, subName string) (*Subscription, error)
CreateSubscription creates a Subscription with the given name if not exists, and returns the subscription instance.
func (*Manager) CreateSubscriptionWithRule ¶
func (m *Manager) CreateSubscriptionWithRule(topicName, subName string, rule *admin.RuleProperties) (*Subscription, error)
CreateSubscriptionWithRule creates a Subscription with the given name and rule if not exists, and returns the subscription instance.
func (*Manager) CreateTopic ¶
CreateTopic creates a Topic with the given name if not exists, and returns the topic instance.
func (*Manager) DeleteQueue ¶
DeleteQueue deletes a Queue with the given name if exists.
func (*Manager) DeleteSubscription ¶
DeleteSubscription deletes a Subscription with the given name if exists.
func (*Manager) DeleteTopic ¶
DeleteTopic deletes a Topic with the given name if exists.
func (*Manager) SetLockDuration ¶
SetLockDuration sets the default lock duration of the queue, it will be used when creating new queue or subscription.
func (*Manager) SetMaxSizeMB ¶
SetMaxSizeMB sets the default max size in megabytes of the queue, it will be used when creating new queue or topic.
func (*Manager) SetMessageTimeToLive ¶
SetMessageTimeToLive sets the default message time to live of the queue, it will be used when creating new queue, topic or subscription.
type Message ¶
type Message struct {
// contains filtered or unexported fields
}
Message represents a message received from Azure Service Bus.
func (*Message) GetAttributes ¶
func (m *Message) GetAttributes() Attributes
GetAttributes returns the attributes of the message.
func (*Message) GetContent ¶
GetContent returns the content of the message in string.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue represents a instance of Azure Service Bus Queue.
func NewQueueWithPeekLockMode ¶
NewQueueWithPeekLockMode creates a new instance of Queue with PeekLock mode.
func NewQueueWithReceiveAndDeleteMode ¶
NewQueueWithReceiveAndDeleteMode creates a new instance of Queue with ReceiveAndDelete mode.
func (*Queue) Complete ¶
Complete marks a message as completed, so it will be deleted from the queue.
func (*Queue) Receive ¶
Receive returns at most 10 messages from the queue. It returns no error if no message is available. Don't call Receive() concurrently, or would be blocked by the mutex.
func (*Queue) Schedule ¶
Schedule schedules a message to be enqueue at the given time, and returns the sequence number of the message.
type Status ¶
type Status struct { SizeInBytes int64 `json:"size_bytes,omitempty"` TotalMessageCount int64 `json:"total_message,omitempty"` ActiveMessageCount int32 `json:"active_message,omitempty"` DeadLetterMessageCount int32 `json:"dead_letter_message,omitempty"` ScheduledMessageCount int32 `json:"scheduled_message,omitempty"` SubscriptionCount int32 `json:"subscription,omitempty"` TransferMessageCount int32 `json:"transfer_message,omitempty"` TransferDeadLetterMessageCount int32 `json:"transfer_dead_letter_message,omitempty"` }
Status represents the status of a queue or topic.
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
Subscription wraps the Azure Service Bus subscription of a topic.
func (*Subscription) Abandon ¶
func (s *Subscription) Abandon(m *Message) error
Abandon marks a message as not taken, so it will be returned immediately.
func (*Subscription) Close ¶
func (s *Subscription) Close() error
Close closes the receiver of the subscription.
func (*Subscription) Complete ¶
func (s *Subscription) Complete(m *Message) error
Complete marks a message as completed, so it will be deleted from the queue.
func (*Subscription) GetStatus ¶
func (s *Subscription) GetStatus() (*Status, error)
GetStatus returns the status of the subscription.
func (*Subscription) Receive ¶
func (s *Subscription) Receive() ([]*Message, error)
Receive returns at most 10 messages from the queue. It returns no error if no message is available. Don't call Receive() concurrently, or would be blocked by the mutex.
func (*Subscription) String ¶
func (s *Subscription) String() string
func (*Subscription) Take ¶
func (s *Subscription) Take(m *Message) error
Take marks a message as taken, so it will not be returned before the visibility timeout. It usually used to extend the time to process the message.
type Topic ¶
type Topic struct {
// contains filtered or unexported fields
}
Topic wraps the Azure Service Bus topic and its related subscriptions.
func NewTopic ¶
NewTopic creates a new topic instance with the given connection string and topic name.
func (*Topic) NewSubscription ¶
func (t *Topic) NewSubscription(subName string) (*Subscription, error)
NewSubscription returns the subscription with the given name of the topic. It returns error if the subscription does not exist.
func (*Topic) NewSubscriptionWithPeekLockMode ¶
func (t *Topic) NewSubscriptionWithPeekLockMode(subName string) (*Subscription, error)
NewSubscriptionWithPeekLockMode returns the subscription with the given name of the topic with PeekLock mode. It returns error if the subscription does not exist.
func (*Topic) NewSubscriptionWithReceiveAndDeleteMode ¶
func (t *Topic) NewSubscriptionWithReceiveAndDeleteMode(subName string) (*Subscription, error)
NewSubscriptionWithReceiveAndDeleteMode returns the subscription with the given name of the topic with ReceiveAndDelete mode. It returns error if the subscription does not exist.
func (*Topic) Schedule ¶
Schedule schedules a message to be enqueue at the given time, and returns the sequence number of the message.