Support the ongoing development of Laravel.io →
posted 11 years ago
Queues

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.

Last updated 3 years ago.
0

Can you just queue the firing of the function and then when that queue job fires run the loop?

Last updated 3 years ago.
0

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.

Last updated 3 years ago.
0

super late reply, but how did you create the $messages array?

I can't find a way to create the individual payloads

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

arnaslu arnaslu Joined 7 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.