Skip to content

Commit 2a69cac

Browse files
committed
rabbit mq 测试qos和手动act
1 parent a9c9a36 commit 2a69cac

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/main/java/com/code/repository/study/rabbitmq/SenderMQ.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class SenderMQ {
2727
private static String QUEUE_NAME = "q1";
2828
private static String EXCHANGE = "hm.direct";
2929

30-
public static void main(String[] args) throws IOException, TimeoutException {
30+
public static void main(String[] args) throws IOException, TimeoutException, InterruptedException {
3131
// connection是socket连接的抽象,并且为我们管理协议版本协商(protocol version negotiation),
3232
// 认证(authentication )等等事情。这里我们要连接的消息代理在本地,因此我们将host设为“localhost”。
3333
// 如果我们想连接其他机器上的代理,只需要将这里改为特定的主机名或IP地址。
@@ -49,7 +49,14 @@ public static void main(String[] args) throws IOException, TimeoutException {
4949
for(int i=0;i<30;i++){
5050
String message = "this is the "+i+" message!";
5151
channel.basicPublish(EXCHANGE, QUEUE_NAME, null, message.getBytes("UTF-8"));
52-
System.out.println("send :" +message);
52+
if (channel.waitForConfirms()) {
53+
System.out.println("发送成功");
54+
System.out.println("send :" +message);
55+
} else {
56+
//发送失败这里可进行消息重新投递的逻辑
57+
System.out.println("发送失败");
58+
System.out.println("send :" +message);
59+
}
5360
}
5461

5562
channel.close();

0 commit comments

Comments
 (0)