Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
utils
Overview
Overview
Details
Activity
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
golang kittool
utils
Commits
551bae76
Commit
551bae76
authored
May 06, 2022
by
feidy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
QueueMsg add “tag” field
parent
0a9cacaf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
3 deletions
+10
-3
mq.go
queue/mq.go
+2
-1
rocketmq.go
queue/rocketmq.go
+8
-2
No files found.
queue/mq.go
View file @
551bae76
...
...
@@ -2,7 +2,7 @@
* @Author: zhoufei
* @Date: 2022-04-22 15:00:32
* @LastEditors: zhoufei
* @LastEditTime: 2022-0
4-26 10:42:17
* @LastEditTime: 2022-0
5-06 14:34:13
* @FilePath: /utils/queue/mq.go
* @Description: 消息队列interface
*
...
...
@@ -24,6 +24,7 @@ type QueueMsg struct {
Topic
string
`json:"topic"`
Body
[]
byte
`json:"body"`
Info
map
[
string
]
interface
{}
`json:"info"`
Tag
string
`json:"tag"`
}
type
msgOptions
struct
{
...
...
queue/rocketmq.go
View file @
551bae76
...
...
@@ -2,7 +2,7 @@
* @Author: zhoufei
* @Date: 2022-04-22 14:58:25
* @LastEditors: zhoufei
* @LastEditTime: 2022-0
4-26 10:40:57
* @LastEditTime: 2022-0
5-06 14:36:10
* @FilePath: /utils/queue/rocketmq.go
* @Description:rocketmq 工具类
* 注意:rocketmq-client-go/v2 在1.18下会闪退,需要手动更改json-iterator/go 到 v1.1.12 (2022-4-25)
...
...
@@ -62,8 +62,11 @@ func (r *RocketMq) SendMsg(topic string, msg []byte, opts ...MsgOption) (qMsg *Q
opt
(
msgOptions
)
}
var
tag
string
if
msgOptions
.
Tag
!=
""
{
rMsg
.
WithTag
(
msgOptions
.
Tag
)
tag
=
msgOptions
.
Tag
}
if
msgOptions
.
UserProperties
!=
nil
{
...
...
@@ -82,6 +85,7 @@ func (r *RocketMq) SendMsg(topic string, msg []byte, opts ...MsgOption) (qMsg *Q
Body
:
[]
byte
(
msg
),
Topic
:
topic
,
Info
:
map
[
string
]
interface
{}{
"msgId"
:
resp
.
MsgID
},
Tag
:
tag
,
}
return
qmsg
,
err
}
...
...
@@ -110,11 +114,12 @@ func (r *RocketMq) RegisterConsumer(topic string, recevieFunc func(qMsg *QueueMs
for
_
,
opt
:=
range
opts
{
opt
(
msgOptions
)
}
var
tag
string
selector
:=
consumer
.
MessageSelector
{}
if
msgOptions
.
Tag
!=
""
{
selector
.
Type
=
consumer
.
TAG
selector
.
Expression
=
msgOptions
.
Tag
tag
=
msgOptions
.
Tag
}
else
if
msgOptions
.
Sql92
!=
""
{
selector
.
Type
=
consumer
.
SQL92
selector
.
Expression
=
msgOptions
.
Sql92
...
...
@@ -126,6 +131,7 @@ func (r *RocketMq) RegisterConsumer(topic string, recevieFunc func(qMsg *QueueMs
Body
:
msg
.
Body
,
Topic
:
topic
,
Info
:
map
[
string
]
interface
{}{
"msgId"
:
msg
.
MsgId
},
Tag
:
tag
,
})
}
return
consumer
.
ConsumeSuccess
,
nil
...
...
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