-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmockProducer.go
39 lines (33 loc) · 870 Bytes
/
mockProducer.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
38
39
package alice
import (
"github.com/streadway/amqp"
)
// A MockProducer implements the Producer interface
type MockProducer struct {
exchange *Exchange
broker *MockBroker
}
// PublishMessage publishes a message
func (p *MockProducer) PublishMessage(msg []byte, key *string, headers *amqp.Table) {
// Find the queues this message was meant for
var queuesToSendTo []*Queue = make([]*Queue, 0, 10)
for _, q := range p.broker.exchanges[p.exchange] {
if q.bindingKey == *key {
queuesToSendTo = append(queuesToSendTo, q)
}
}
delivery := amqp.Delivery{
Headers: *headers,
ContentType: "",
ContentEncoding: "",
Body: msg,
}
// Send message to the queues
for _, q := range queuesToSendTo {
p.broker.Messages[q] <- delivery
}
}
// Shutdown shuts this producer down
func (p *MockProducer) Shutdown() error {
return nil
}