diff --git a/composer.json b/composer.json index 3248c23..b5a53d3 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,6 @@ "ext-pcntl": "*", "ext-rdkafka": "*", "symfony/serializer": "6.2.x-dev", - "symfony/property-access": "6.2.x-dev", - "symfony/mailer": "6.2.x-dev" + "symfony/property-access": "6.2.x-dev" } } diff --git a/config/config.php b/config/config.php index be766a1..03ba93c 100644 --- a/config/config.php +++ b/config/config.php @@ -84,14 +84,4 @@ | fnv1a_random - FNV-1a hash of key (NULL keys are randomly partitioned). */ 'partitioner' => env('KAFKA_PARTITIONER', 'random'), - - /* - | In order to use our Kafka-based mail server put this piece of code in the config/mail.php file. - | - 'kafka-mailer' => [ - 'transport' => 'kafka-mailer, - 'topic' => env('KAFKA_MAILER_TOPIC'), - ], - | - */ ]; diff --git a/src/KafkaProducerServiceProvider.php b/src/KafkaProducerServiceProvider.php index 7d31840..46e6405 100644 --- a/src/KafkaProducerServiceProvider.php +++ b/src/KafkaProducerServiceProvider.php @@ -4,8 +4,6 @@ namespace Uc\KafkaProducer; -use Uc\KafkaProducer\Transports\KafkaTransport; -use Illuminate\Support\Facades\Mail; use Illuminate\Support\ServiceProvider; use Uc\KafkaProducer\Providers\EventServiceProvider; @@ -55,7 +53,6 @@ public function register() : void * Bootstrap any application services. * * @return void - * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function boot() : void { @@ -67,9 +64,5 @@ public function boot() : void 'kafka-producer-config' ); } - - Mail::extend('kafka-mailer', function ($config) { - return $this->app->make(KafkaTransport::class, ['topic' => $config['topic']]); - }); } } diff --git a/src/Transports/KafkaTransport.php b/src/Transports/KafkaTransport.php deleted file mode 100644 index 56cbd24..0000000 --- a/src/Transports/KafkaTransport.php +++ /dev/null @@ -1,94 +0,0 @@ - - */ -class KafkaTransport extends AbstractTransport -{ - /** - * @var \Illuminate\Events\Dispatcher Reference on the instance of Laravel's Event Dispatcher. - */ - protected Dispatcher $laravelEventDispatcher; - - /** - * @var \Uc\KafkaProducer\MessageBuilder Reference on the instance of MessageBuilder. - */ - protected MessageBuilder $builder; - - /** - * @var string Kafka topic where the e-mail messages should be published. - */ - protected string $topic; - - public function __construct(Dispatcher $laravelEventDispatcher, MessageBuilder $builder, string $topic, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null) - { - parent::__construct($dispatcher, $logger); - - $this->builder = $builder; - $this->topic = $topic; - $this->laravelEventDispatcher = $laravelEventDispatcher; - } - - protected function doSend(SentMessage $message) : void - { - $email = MessageConverter::toEmail($message->getOriginalMessage()); - $body = $this->prepareMessageBody($email); - $kafkaMessage = $this->builder - ->setTopicName($this->topic) - ->setKey($body['from']) - ->setBody($body) - ->getMessage(); - - $this->laravelEventDispatcher->dispatch(new ProduceMessageEvent($kafkaMessage)); - } - - /** - * Prepare Kafka message body. - * - * @param \Symfony\Component\Mime\Email $email - * - * @return array - */ - protected function prepareMessageBody(Email $email) : array - { - return [ - 'from' => $email->getFrom()[0]->toString(), - 'recipients' => array_map(function (Address $address) { - return $address->getAddress(); - }, $email->getTo()), - 'subject' => $email->getSubject(), - 'body' => $email->getHtmlBody(), - ]; - } - - /** - * Get the string representation of the transport. - * - * @return string - */ - public function __toString() : string - { - return 'kafka-mailer'; - } -}