-
Notifications
You must be signed in to change notification settings - Fork 2
/
stub.go
56 lines (41 loc) · 1.2 KB
/
stub.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package babex
type StubMessage struct{}
// Use stub message for Catch without ack/nack
func NewStubMessage(initialMessage *InitialMessage, exchange string, key string) *Message {
msg := NewMessage(initialMessage, exchange, key)
msg.RawMessage = StubMessage{}
return msg
}
func (sm StubMessage) Ack() error {
return nil
}
func (sm StubMessage) Nack() error {
return nil
}
type StubAdapter struct {
OutCh chan *Message
OutChannels Channels
Err chan error
onPublish func(exchange string, key string, message InitialMessage) error
}
func (stub *StubAdapter) GetMessages() (<-chan *Message, error) {
return stub.OutCh, nil
}
func (stub *StubAdapter) GetErrors() chan error {
return stub.Err
}
func (stub *StubAdapter) Publish(exchange string, key string, message InitialMessage) error {
return stub.onPublish(exchange, key, message)
}
func (stub *StubAdapter) Close() error {
return nil
}
func (stub *StubAdapter) Channels() Channels {
return stub.OutChannels
}
type StubMiddleware struct {
OnUse func(s *Service, msg *Message) (MiddlewareDone, error)
}
func (stubMiddleware StubMiddleware) Use(s *Service, msg *Message) (MiddlewareDone, error) {
return stubMiddleware.OnUse(s, msg)
}