How do you add large amounts of messages to the queue? If I run Queue:push() in a loop it looks like every call sends separate request to the driver (IronMQ in my case), so this:
for ($i = 0; $i < 1000; $i++) {
Queue::push('test', ['message' => $i]);
}
takes a few minutes.
Using IronMQ SDK you can send messages in bulk using
$mq->postMessages($queue, $messages);
where $messages could contain an array of 5k messages and it would take a second or two to send out, but I'd like to use Laravel for that so I could switch providers if necessary.
From looking at documentation I see Laravel has bulk method, but it's used for pushing to multiple queues and not for pushing multiple messages to the same queue.
Can you just queue the firing of the function and then when that queue job fires run the loop?
awestrope said:
Can you just queue the firing of the function and then when that queue job fires run the loop?
That seems redundant. What I'd like to do is something like this:
for ($i = 0; $i < 1000; $i++) {
Queue::add("message");
}
Queue::pushAll("queue_name");
where pushAll() would use native driver's bulk/batch API (I know IronMQ and SQS has it, not sure about the others) or use foreach loop to push each message if driver has no bulk/batch API.
For now I think I'll just use native client like this:
Queue::getIron()->postMessages("queue_name", $messages);
and work on more elegant solution when I have some free time.
super late reply, but how did you create the $messages array?
I can't find a way to create the individual payloads
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community