8000 Queue spool. by makasim · Pull Request #970 · swiftmailer/swiftmailer · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Nov 17, 2021. It is now read-only.

Queue spool. #970

Closed
wants to merge 5 commits into from
Closed
8000

Queue spool. #970

wants to merge 5 commits into from

Conversation

makasim
Copy link
@makasim makasim commented Jul 26, 2017

PR adds an ability to use any queue-interop compatible MQ transport as an email spool.

Here's use case example, the source code is here:

<?php

// send.php
// could be run as GUSER=yourAccountName@gmail.com GPASS="yourGmailPassword" php send.php

require_once __DIR__.'/vendor/autoload.php';

$transport = new Swift_SpoolTransport(new \Swift_QueueSpool(
    (new \Enqueue\Fs\FsConnectionFactory('file://'.__DIR__.'/queue'))->createContext()
));

$mailer = new Swift_Mailer($transport);

$message = (new Swift_Message('Wonderful Subject'))
    ->setFrom(getenv('GUSER'))
    ->setTo(getenv('GUSER'))
    ->setBody('Here is the message itself. Sent at: '.date('Y-m-d H:i:s'))
;

$result = $mailer->send($message);

The message was queued, to send message for real we have to flush queue.

<?php

// consume.php
// GUSER=yourAccountName@gmail.com GPASS="yourGmailPassword" php consume.php

require_once __DIR__.'/vendor/autoload.php';

$transport = new Swift_SpoolTransport(new \Swift_QueueSpool(
    (new \Enqueue\Fs\FsConnectionFactory('file://'.__DIR__.'/queue'))->createContext()
));

/** @var \Swift_QueueSpool $spool */
$spool = $transport->getSpool();
$spool->setTimeLimit(3);

$realTransport = (new Swift_SmtpTransport('smtp.gmail.com', 465, 'ssl'))
    ->setUsername(getenv('GUSER'))
    ->setPassword(getenv('GPASS'))
;

$spool->flushQueue($realTransport);

TODO:

  • tests
  • docs.
  • TBD PsrProcessor

makasim pushed a commit to formapro-forks/swiftmailer that referenced this pull request Jul 26, 2017
@makasim
Copy link
Author
makasim commented Jul 26, 2017

@fabpot Will you merge this? If so, I am going to add some tests and docs

Copy link
Contributor
@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a cool idea. So you could have one application using this spool adding messages on the queue and another application reading for the queue.

< 8000 /div>
{
$this->context = $context;

if (false == $queue instanceof PsrQueue) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

===

use Interop\Queue\ExceptionInterface as PsrException;
use Interop\Queue\PsrContext;
use Interop\Queue\PsrQueue;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some class docs would be preferred.

*/
public function __construct(PsrContext $context, $queue = 'swiftmailer_spool')
{
$this->context = $context;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be moved to the bottom of the block. It will make the code a (tiny) bit easier to read.

@makasim
Copy link
Author
makasim commented Jan 15, 2018

@Nyholm done

@makasim
Copy link
85D1
Author
makasim commented Jan 15, 2018

Added amqp interop optimized spool mailer

@makasim makasim closed this Sep 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0