Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
im-pool
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
haoyanbin
im-pool
Commits
eca82664
Commit
eca82664
authored
Nov 18, 2022
by
haoyanbin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Conf
parent
d3c3d90e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
16 deletions
+23
-16
rabbitmq.go
dao/mq/rabbitmq.go
+1
-1
client.go
pool/client.go
+1
-1
publicApi.go
pool/publicApi.go
+5
-5
ws_client.go
ws_client.go
+1
-1
ws_server.go
ws_server.go
+15
-8
No files found.
dao/mq/rabbitmq.go
View file @
eca82664
...
@@ -5,7 +5,7 @@ import (
...
@@ -5,7 +5,7 @@ import (
"github.com/streadway/amqp"
"github.com/streadway/amqp"
)
)
var
mqUrl
=
"amqp://admin:admin@1
27.0.0.1
:5672/"
var
mqUrl
=
"amqp://admin:admin@1
72.17.36.64
:5672/"
// 除了simple 模式外、其他的模式都是由 队列 交换机 key 不同组合实现的
// 除了simple 模式外、其他的模式都是由 队列 交换机 key 不同组合实现的
type
RabbitMQ
struct
{
type
RabbitMQ
struct
{
...
...
pool/client.go
View file @
eca82664
...
@@ -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"
...
...
pool/publicApi.go
View file @
eca82664
...
@@ -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
}
}
...
...
ws_client.go
View file @
eca82664
...
@@ -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
<
5
0
;
i
++
{
go
wsClient2
(
fmt
.
Sprintf
(
"lA6fUNMamyUBlOokPOeiGg==_1_%d"
,
i
))
go
wsClient2
(
fmt
.
Sprintf
(
"lA6fUNMamyUBlOokPOeiGg==_1_%d"
,
i
))
}
}
select
{}
select
{}
...
...
ws_server.go
View file @
eca82664
...
@@ -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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment