Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
platform
/
platform-execute-server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 1c9c543f
authored
Sep 20, 2023
by
周杭
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
mq消费着手动ack
1 parent
114e992c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
2 deletions
platform-execute/src/main/java/cn/com/glsx/execute/modules/rabbitmq/consumer/DirectReceiver.java
platform-execute/src/main/java/cn/com/glsx/execute/modules/rabbitmq/consumer/DirectReceiver.java
View file @
1c9c543
package
cn
.
com
.
glsx
.
execute
.
modules
.
rabbitmq
.
consumer
;
package
cn
.
com
.
glsx
.
execute
.
modules
.
rabbitmq
.
consumer
;
import
cn.com.glsx.execute.modules.rabbitmq.produce.RabbitConfig
;
import
cn.com.glsx.execute.modules.rabbitmq.produce.RabbitConfig
;
import
com.rabbitmq.client.Channel
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.amqp.core.Message
;
import
org.springframework.amqp.rabbit.annotation.*
;
import
org.springframework.amqp.rabbit.annotation.*
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.io.IOException
;
@Component
@Component
@Slf4j
@Slf4j
public
class
DirectReceiver
{
public
class
DirectReceiver
{
...
@@ -15,8 +19,15 @@ public class DirectReceiver {
...
@@ -15,8 +19,15 @@ public class DirectReceiver {
}
}
@RabbitListener
(
queues
=
RabbitConfig
.
BURYING_POINT_QUEUE
)
//监听的队列名称
@RabbitListener
(
queues
=
RabbitConfig
.
BURYING_POINT_QUEUE
)
//监听的队列名称
public
void
buryingPointListener
(
String
testMessage
)
{
public
void
buryingPointListener
(
Message
message
,
Channel
channel
)
throws
IOException
{
log
.
info
(
"burying_point_queue消费-----------{}"
,
testMessage
);
try
{
log
.
info
(
"burying_point_queue消费-----------{}"
,
new
String
(
message
.
getBody
()));
channel
.
basicAck
(
message
.
getMessageProperties
().
getDeliveryTag
(),
false
);
}
catch
(
Exception
e
)
{
// 两个布尔值,若第二个设为false,则丢弃该消息;若设为true,则返回给队列
channel
.
basicNack
(
message
.
getMessageProperties
().
getDeliveryTag
(),
false
,
true
);
System
.
out
.
println
(
"消费失败 消息将返回给队列"
);
}
}
}
@RabbitListener
(
queues
=
RabbitConfig
.
FANOUT_QUEUE1
)
@RabbitListener
(
queues
=
RabbitConfig
.
FANOUT_QUEUE1
)
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment