Commit eca82664 authored by haoyanbin's avatar haoyanbin

Conf

parent d3c3d90e
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"github.com/streadway/amqp" "github.com/streadway/amqp"
) )
var mqUrl = "amqp://admin:admin@127.0.0.1:5672/" var mqUrl = "amqp://admin:admin@172.17.36.64:5672/"
// 除了simple 模式外、其他的模式都是由 队列 交换机 key 不同组合实现的 // 除了simple 模式外、其他的模式都是由 队列 交换机 key 不同组合实现的
type RabbitMQ struct { type RabbitMQ struct {
......
...@@ -26,7 +26,7 @@ const ( ...@@ -26,7 +26,7 @@ const (
// //
closeWait = 60 * 30 * time.Second closeWait = 60 * 30 * time.Second
// time for auto end // time for auto end
endDate = 60 * 2 * time.Second endDate = 60 * 10 * time.Second
) )
var cliKey = "clients" var cliKey = "clients"
......
...@@ -76,7 +76,7 @@ func NewClient(conf *Config) *Client { ...@@ -76,7 +76,7 @@ func NewClient(conf *Config) *Client {
client.OnPing(nil) client.OnPing(nil)
client.OnPong(nil) client.OnPong(nil)
wsSever.hub.AddClient(client) wsSever.hub.AddClient(client)
AppendClient(client.Id,string(SerializeJson(conf))) AppendClient(client.Id, string(SerializeJson(conf)))
return client return client
} }
...@@ -310,7 +310,7 @@ func GetList(source, userType string) map[string]*Client { ...@@ -310,7 +310,7 @@ func GetList(source, userType string) map[string]*Client {
clientData := make(map[string]*Client, 0) clientData := make(map[string]*Client, 0)
for k, v := range wsSever.hub.clients { for k, v := range wsSever.hub.clients {
userInfo := strings.Split(k, "_") userInfo := strings.Split(k, "_")
if userInfo[0] == source { if (userInfo[0] == source) || (source == "") {
if userType != "" { if userType != "" {
if userInfo[1] == userType { if userInfo[1] == userType {
clientData[k] = v clientData[k] = v
...@@ -474,7 +474,7 @@ func SaveMsg(msg *SendMsg) { ...@@ -474,7 +474,7 @@ func SaveMsg(msg *SendMsg) {
mqData.EndTime = msg.SendTime mqData.EndTime = msg.SendTime
mqData.Promoter = user.Promoter mqData.Promoter = user.Promoter
mqData.Finish = "5" mqData.Finish = "5"
DelConversation(msg.FromClientId,msg.ToClientId) DelConversation(msg.FromClientId, msg.ToClientId)
} }
if mqData.ProcedureType != 0 { if mqData.ProcedureType != 0 {
...@@ -518,11 +518,11 @@ func AppendConversation(conversation *Conversation) { ...@@ -518,11 +518,11 @@ func AppendConversation(conversation *Conversation) {
} }
func DelConversation(customerClientId, userClientId string) { func DelConversation(customerClientId, userClientId string) {
Redis.HDel(convKey, customerClientId + "^" + userClientId) Redis.HDel(convKey, customerClientId+"^"+userClientId)
return return
} }
func AppendClient(clientId, data string){ func AppendClient(clientId, data string) {
Redis.HSet(cliKey, clientId, data) Redis.HSet(cliKey, clientId, data)
return return
} }
......
...@@ -18,7 +18,7 @@ var addr2 = flag.String("addr", "127.0.0.1:11001", "http service address") ...@@ -18,7 +18,7 @@ var addr2 = flag.String("addr", "127.0.0.1:11001", "http service address")
func main() { func main() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())
for i := 1; i < 5; i++ { for i := 1; i < 50; i++ {
go wsClient2(fmt.Sprintf("lA6fUNMamyUBlOokPOeiGg==_1_%d", i)) go wsClient2(fmt.Sprintf("lA6fUNMamyUBlOokPOeiGg==_1_%d", i))
} }
select {} select {}
......
...@@ -76,7 +76,7 @@ func ws(w http.ResponseWriter, r *http.Request) { ...@@ -76,7 +76,7 @@ func ws(w http.ResponseWriter, r *http.Request) {
userInfo, err := pool.GetClientInfoByToken(headData) userInfo, err := pool.GetClientInfoByToken(headData)
if err != nil { if err != nil {
fmt.Println("用户信息报错:",err) fmt.Println("用户信息报错:", err)
return return
} }
...@@ -181,14 +181,21 @@ func ws(w http.ResponseWriter, r *http.Request) { ...@@ -181,14 +181,21 @@ func ws(w http.ResponseWriter, r *http.Request) {
} }
func GetClientList(w http.ResponseWriter, r *http.Request) { func GetClientList(w http.ResponseWriter, r *http.Request) {
//fmt.Println(wsSever.hub.clients)
data := r.URL.Query() data := r.URL.Query()
//req := new(GetClientListReq) list := pool.GetList(data["source"][0], data["promoter"][0])
//pool.UnserislizeJson(data, req)
//source := data["source"][0] reply := make([]string, 0)
reply := pool.GetList(data["source"][0], data["promoter"][0]) for k := range list {
fmt.Println("客户端列表:",reply) reply = append(reply, k)
return }
resp(w,reply)
}
func resp(w http.ResponseWriter,data interface{}){
w.Header().Set("content-type", "text/json")
w.WriteHeader(200)
w.Write(pool.SerializeJson(data))
} }
type GetClientListReq struct { type GetClientListReq struct {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment