Commit d888eef 1 parent 45ba85e commit d888eef Copy full SHA for d888eef
File tree 1 file changed +21
-4
lines changed
mq-cloud/src/main/resources/static/wiki/userGuide
1 file changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -41,14 +41,18 @@ sendMessage()
41
41
# coding=utf-8
42
42
import requests
43
43
import time
44
+ import signal
45
+
46
+ # 是否运行变量
47
+ running = True
44
48
45
49
def httpConsume():
46
50
# 定义消费消息的参数
47
51
payload = {'topic': 'mqcloud-http-test-topic', 'consumer': 'clustering-mqcloud-http-consumer'}
48
- while True :
52
+ while running :
49
53
try:
50
54
# 拉取消息
51
- response = requests.post ('http://${httpConsumerUriPrefix}/mq/message', data =payload)
55
+ response = requests.get ('http://${httpConsumerUriPrefix}/mq/message', params =payload)
52
56
# 解析响应结果
53
57
if response.status_code == 200:
54
58
data = response.json()
@@ -74,9 +78,22 @@ def httpConsume():
74
78
print('reqeust error', e)
75
79
76
80
# 延时一会
77
- time.sleep(2)
81
+ if running:
82
+ time.sleep(2)
83
+
84
+ # 进程退出时,提交ACK
85
+ try:
86
+ requests.get('http://${httpConsumerUriPrefix}/mq/ack', params=payload)
87
+ except Exception as e:
88
+ print('ack error', e)
89
+
90
+ def signal_handler(sig, frame):
91
+ global running
92
+ running = False
93
+
94
+ signal.signal(signal.SIGINT, signal_handler)
95
+ signal.signal(signal.SIGTERM, signal_handler)
78
96
79
- # 消费消息
80
97
httpConsume()
81
98
```
82
99
You can’t perform that action at this time.
0 commit comments