-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpicker.go
37 lines (34 loc) · 890 Bytes
/
picker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package carrot
//Picker just pick message from queue without continuous consuming
type Picker struct {
client *BrokerClient
}
//Pick item from queue
func (get *Picker) Pick(queue string) (*MessageContext, bool, error) {
if ch, err := get.client.client.Channel(); err != nil {
return nil, false, err
} else {
if msg, ok, err := ch.Get(queue, false); err != nil {
return nil, false, err
} else if ok {
context := new(MessageContext)
context.delivery = msg
context.channel = ch
context.Message = Message{
ContentType: msg.ContentType,
Data: msg.Body,
Encoding: msg.ContentEncoding,
Headers: msg.Headers,
}
return context, ok, nil
} else {
return nil, ok, nil
}
}
}
//NewPicker creates a new broker queue picker
func NewPicker(client *BrokerClient) *Picker {
picker := new(Picker)
picker.client = client
return picker
}