Я развернул RabbitMQ на сервере EC2. Когда я впервые публикую несколько сообщений в очереди, время обработки так быстро. После обработки этих сообщений я публикую больше некоторых сообщений, но время обработки очень медленное.
def get_queue_length(self,str_queue_name):
if str_queue_name is LIST_CAMPAIGN_QUEUE:
return self.obj_requester_channel.queue_declare(str_queue_name).method.message_count
print("check queue customer")
return self.obj_campaign_channel.queue_declare(str_queue_name).method.message_count
@timeout(20)
def get_message_by_campaign_id(self,campaign_id, n_message):
start = time.time()
print("START",datetime.datetime.now().time())
str_campaign_queue_name = "Campaign~" + campaign_id
while True:
try:
self.obj_campaign_channel.queue_declare(queue=str_campaign_queue_name)
break
except pika.exceptions.ConnectionWrongStateError:
self.create_connection()
continue
n_msg_in_queue = self.get_queue_length(str_campaign_queue_name)
print("we will claim", str(n_message), "message(s) over", str(n_msg_in_queue))
# Start receive messages in queue
i = 0
l_some_message = list()
print("MID",datetime.datetime.now().time())
Вывод:
Start Listening !!!
START 04:22:20.062826
MID~1 04:22:20.067087
check queue customer
!!!!!!!!!!!!!!!!!!!!!!
we will claim 1 message(s) over 1
MID-2 04:22:20.069996
{"FileName": "template/template01.json", "ActionStamp": "osam$$6$$38$$20190904100000", "Contact": [{"email": "osam.dungpham@gmail.com"}, {"first_name": "Dung Pham"}], "CampaignID": "osam$$6$$38$$20190904100000"}
Requeued 0 messages
Done for Campaign~osam$$6$$38$$20190904100000
END 04:22:20.076652
TIME: 0.013826847076416016
Затем, после нажатия некоторых сообщений:
START 05:10:24.234919
MID~1 05:10:29.265223
check queue customer
!!!!!!!!!!!!!!!!!!!!!!
we will claim 1 message(s) over 1
MID-2 05:10:29.268592
{"FileName": "template/template01.json", "ActionStamp": "osam$$6$$38$$20190904100000", "Contact": [{"email": "osam.dungpham@gmail.com"}, {"first_name": "Dung Pham"}], "CampaignID": "osam$$6$$38$$20190904100000"}
Requeued 0 messages
Done for Campaign~osam$$6$$38$$20190904100000
END 05:10:34.300592
TIME: 10.065659999847412