I have a running Symfony 4.4 project with messenger and rabbitMQ. I have an async transport with 2 queues.
transports:
# https://symfony.com/doc/current/messenger.html#transport-configuration
async:
dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
options:
exchange:
name: myexchange
type: direct
queues:
email:
binding_keys:
- email
extranet:
binding_keys:
- extranet
# failed: 'doctrine://default?queue_name=failed'
# sync: 'sync://'
routing:
# Route your messages to the transports
'App\Message\ExtranetMessage': async
'Symfony\Component\Mailer\Messenger\SendEmailMessage': async
I need to send email with the symfony/mailer
component to the email queue.
public function contact(Request $request, MailerInterface $mailer)
{
if($request->isXmlHttpRequest())
{
//dd($request->request->all());
$body =
'Nouveau message depuis le front<br />
Nom = '.$request->request->get('nom').'<br />
Prénom = '.$request->request->get('prenom').'<br />
Société = '.$request->request->get('societe').'<br />
Email = '.$request->request->get('mail').'<br />';
$email = (new Email())
->from('[email protected]')
->replyTo($request->request->get('mail'))
->to('$request->request->get('mail')')
->subject('test')
->html($body);
$mailer->send($email);
return new JsonResponse('OK', 200);
}
}
How can I add the binding_key to the mailer
in order to let rabbitMQ know how to handle the email ?
Allright, I found the answer while searching for the complete messenger configuration reference.
In order to process messages without binding key, a
default_publish_routing_key
entry has to be added. The configuration now looks like :This allows the messenger component to process messages event if they don't have any queue specified.