回调状态修改

This commit is contained in:
AKW 2023-12-22 14:15:34 +08:00
parent 84f5505948
commit 3130d49276
3 changed files with 4 additions and 51 deletions

View File

@ -1,26 +0,0 @@
import json
from redis import StrictRedis
rc = StrictRedis(host='localhost', port=6379, db=0)
data = {
"create_time": 1671796836,
"update_time": 1671796836,
"remark": "test message",
"corp_id": 12345,
"vid": 123456789,
"msg_type": 1,
"to_vid": 987654321,
"to_room_id": 1122334455,
"send_time": "1671705497",
"content": "this is a test message",
"aeskey": "123456789abcdefg",
"origin_data": {
"foo": "bar"
}
}
for i in range(10):
value_new = json.dumps(data)
rc.publish("jqr:msg", value_new)

View File

@ -1,25 +0,0 @@
import time
from redis import StrictRedis
import json
rc = StrictRedis(host='localhost', port=6379, db=0)
ps = rc.pubsub()
ps.subscribe('jqr:msg')
msg_list = []
batch_size = 2
while True:
for item in ps.listen():
if item['type'] == 'message':
data = item.get('data')
print(data)
msg_list.append(data)
if len(msg_list) >= batch_size:
try:
time.sleep(1)
msg_list = msg_list[-batch_size:]
except Exception as e:
print(e)
print(len(msg_list))

View File

@ -1,4 +1,5 @@
import json
import logging
from redis import Redis
from django.conf import settings
@ -7,6 +8,8 @@ from threading import Thread
from apps.msg.models import TbMessage
from yzk_wechat_event.settings.constant import Constant
logger = logging.getLogger('apps')
class JQRMSGPubSubUtils:
rc = Redis(host=settings.REDIS_HOST, port=settings.REDIS_PORT, db=0)
@ -19,6 +22,7 @@ class JQRMSGPubSubUtils:
def listen():
logger.info('监听消息队列-----')
from apps.jqr.serializers import TbMessageModelSerializer
while True:
data = JQRMSGPubSubUtils.rc.brpop(Constant.JQR_MSG_PUBSUB_CHANNEL, 5)