-
Notifications
You must be signed in to change notification settings - Fork 1
/
event_client.go
37 lines (34 loc) · 990 Bytes
/
event_client.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 synapse
import (
"github.com/streadway/amqp"
"fmt"
"encoding/json"
)
/**
发送一个事件
*/
func (s *Server) eventClient() {
s.eventClientChannel = s.CreateChannel(0, "EventClient")
}
func (s *Server) SendEvent(eventName string, params map[string]interface{}) {
if s.DisableEventClient {
Log("Event Client Disabled: DisableEventClient set true", LogError)
} else {
query, _ := json.Marshal(params);
s.eventClientChannel.Publish(
s.SysName, // exchange
fmt.Sprintf("event.%s.%s", s.AppName, eventName), // routing key
false, // mandatory
false, // immediate
amqp.Publishing{
MessageId: s.randomString(20),
AppId: s.AppId,
ReplyTo: s.AppName,
Type: eventName,
Body: query,
})
if s.Debug {
Log(fmt.Sprintf("Event Publish: %s@%s %s", eventName, s.AppName, query), LogDebug)
}
}
}