Custom email queue backed by database

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
jafo66
Posts: 75
Joined: 06 Mar 2024, 04:42

Custom email queue backed by database

Post by jafo66 » 06 Jun 2025, 15:19

Based on some business logic, I need to create an email queue backed by a database table. I've tried to follow what the AI chat gave me but I'm missing a key piece.

I created my database queue handler class in my extension: packages/mypackage/src/MQueue/Queue/DBQueue.php

namespace MQueue/Queue

In my config/shop.php, I have added the following:

Code: Select all

'resource' => [
		... all the other standard stuff above this entry
		'queue' => [
			'mq-team' => [
				'standard' => [
					'class' => \MQueue\Queue\DBQueueTeam::class,
				],
			],
		]
I'm using the following to read/write to the queue:

Code: Select all

$queue = $context->queue('mq-team', 'team/coachassign');
$queue->get();
My 2 questions:
  1. How do I properly configure the queue to use database class noted above?
  2. What configuration do I need to add to enable the madmin_queue capabilities I see in: https://github.com/aimeos/aimeos-base/b ... andard.php

jafo66
Posts: 75
Joined: 06 Mar 2024, 04:42

Re: Custom email queue backed by database

Post by jafo66 » 06 Jun 2025, 15:33

On question #2, it looks like I just needed to modify the config/queue.php by changing the 'default' to be database. I will configure the .env file instead of making that hardcoded change just to confirm.

Is that the correct approach?

User avatar
aimeos
Administrator
Posts: 8616
Joined: 01 Jan 1970, 00:00

Re: Custom email queue backed by database

Post by aimeos » 06 Jun 2025, 20:52

Unfortunately, the AI in the chat often mixes up things it learned from other code bases but which isn't applicable in Aimeos :-/

Using DB based queues is really simple and all you need is explained here:
https://aimeos.org/docs/latest/infrastr ... age-queues

Add a message to a queue:

Code: Select all

$queue = $this->context()
    ->queue( 'mq-email', 'order/email/payment' )
    ->add( json_encode( ['email' => 'me@example.com'] ) );
Get the messages in a job controller sending the emails:

Code: Select all

$queue = $this->context()->queue( 'mq-email', 'order/email/payment' );

while( $msg = $queue->get() )
{
    $data = json_decode( $msg->getBody() );
    // perform the task
    $queue->del( $msg );
}
The "mq-email" is the key to the configuration of the queue manager if your have several queue services like DB, RabbitMQ, etc. and if it doesn't exist, it falls back to "mq" configuration defined in your ./config/shop.php. The "order/email/payment" is the name of the actual queue which you use and it can be any string. We use the path of the job controller to know easily know where the queue belongs to.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

jafo66
Posts: 75
Joined: 06 Mar 2024, 04:42

Re: Custom email queue backed by database

Post by jafo66 » 06 Jun 2025, 23:15

How do I configure my own database backed class for a specific queue type ex: my-team?

It seemed like I just needed to add a configuration line item, is there something else much more difficult?

Thanks!

User avatar
aimeos
Administrator
Posts: 8616
Joined: 01 Jan 1970, 00:00

Re: Custom email queue backed by database

Post by aimeos » 07 Jun 2025, 10:07

Use this config for your own queue class:

Code: Select all

'mq' => [
	'adapter' => 'DBQueueTeam',
	// implementation specific configuration
	// ...
],
You can see how other queue adapters are implemented here: https://github.com/aimeos/ai-mqueue
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply