-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.go
39 lines (31 loc) · 1.23 KB
/
interface.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 mqrpc
import "time"
// type MessageService interface {
// Identifier() string
// Send(to, msgType string, payload interface{}) error
// SendToAny(msgType string, payload interface{}) error
// Broadcast(msgType string, payload interface{}) error
// Request(to, msgType string, payload interface{}, timeout time.Duration) (interface{}, error)
// }
type DefaultMessageService struct {
MqService *MqService
}
func (m *DefaultMessageService) Identifier() string {
return m.MqService.peerName
}
func (m *DefaultMessageService) Send(to, msgType string, payload interface{}) error {
return m.MqService.fireAndForget(to, MsgType(msgType), payload, false)
}
func (m *DefaultMessageService) SendToAny(msgType string, payload interface{}) error {
return m.MqService.fireAndForget("", MsgType(msgType), payload, false)
}
func (m *DefaultMessageService) Broadcast(msgType string, payload interface{}) error {
return m.MqService.fireAndForget("", MsgType(msgType), payload, true)
}
func (m *DefaultMessageService) Request(to, msgType string, payload interface{}, timeout time.Duration) (interface{}, error) {
msg, err := m.MqService.sendAndWaitReply(to, MsgType(msgType), payload, timeout)
if err != nil {
return nil, err
}
return msg.Payload, nil
}