Skip to content

[client] Add ability to preapre message, or use no JSON format. #339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions pkg/enqueue/Client/ChainExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,33 @@ public function __construct(array $extensions)
$this->extensions = $extensions;
}

/**
* @param OnPrepareMessage $context
*/
public function onPrepareMessage(OnPrepareMessage $context)
{
foreach ($this->extensions as $extension) {
$extension->onPrepareMessage($context);
}
}

/**
* {@inheritdoc}
*/
public function onPreSend($topic, Message $message)
public function onSend(OnSend $context)
{
foreach ($this->extensions as $extension) {
$extension->onPreSend($topic, $message);
$extension->onSend($context);
}
}

/**
* {@inheritdoc}
*/
public function onPostSend($topic, Message $message)
public function onPostSend(OnPostSend $context)
{
foreach ($this->extensions as $extension) {
$extension->onPostSend($topic, $message);
$extension->onPostSend($context);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
namespace Enqueue\Client\ConsumptionExtension;

use Enqueue\Client\Config;
use Enqueue\Client\EmptyExtensionTrait as ClientEmptyExtensionTrait;
use Enqueue\Client\ExtensionInterface as ClientExtensionInterface;
use Enqueue\Client\Message;
use Enqueue\Client\OnSend;
use Enqueue\Consumption\Context;
use Enqueue\Consumption\EmptyExtensionTrait;
use Enqueue\Consumption\EmptyExtensionTrait as ConsumptionEmptyExtensionTrait;
use Enqueue\Consumption\ExtensionInterface as ConsumptionExtensionInterface;

class ExclusiveCommandExtension implements ConsumptionExtensionInterface, ClientExtensionInterface
{
use EmptyExtensionTrait;
use ConsumptionEmptyExtensionTrait;
use ClientEmptyExtensionTrait;

/**
* @var string[]
Expand Down Expand Up @@ -63,23 +65,18 @@ public function onPreReceived(Context $context)
/**
* {@inheritdoc}
*/
public function onPreSend($topic, Message $message)
public function onSend(OnSend $context)
{
if (Config::COMMAND_TOPIC != $topic) {
if (false == $context->getCommand()) {
return;
}

$message = $context->getMessage();

$commandName = $message->getProperty(Config::PARAMETER_COMMAND_NAME);
if (array_key_exists($commandName, $this->processorNameToQueueNameMap)) {
$message->setProperty(Config::PARAMETER_PROCESSOR_NAME, $commandName);
$message->setProperty(Config::PARAMETER_PROCESSOR_QUEUE_NAME, $this->processorNameToQueueNameMap[$commandName]);
}
}

/**
* {@inheritdoc}
*/
public function onPostSend($topic, Message $message)
{
}
}
27 changes: 27 additions & 0 deletions pkg/enqueue/Client/EmptyExtensionTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Enqueue\Client;

trait EmptyExtensionTrait
{
/**
* {@inheritdoc}
*/
public function onPrepareMessage(OnPrepareMessage $context)
{
}

/**
* {@inheritdoc}
*/
public function onSend(OnSend $context)
{
}

/**
* {@inheritdoc}
*/
public function onPostSend(OnPostSend $context)
{
}
}
19 changes: 9 additions & 10 deletions pkg/enqueue/Client/ExtensionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
interface ExtensionInterface
{
/**
* @param string $topic
* @param Message $message
*
* @return
* @param OnPrepareMessage $context
*/
public function onPreSend($topic, Message $message);
public function onPrepareMessage(OnPrepareMessage $context);

/**
* @param string $topic
* @param Message $message
*
* @return
* @param OnSend $context
*/
public function onPostSend($topic, Message $message);
public function onSend(OnSend $context);

/**
* @param OnPostSend $context
*/
public function onPostSend(OnPostSend $context);
}
52 changes: 52 additions & 0 deletions pkg/enqueue/Client/OnPostSend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Enqueue\Client;

class OnPostSend
{
/**
* @var Message
*/
private $message;

/**
* @var string|null
*/
private $topic;

/**
* @var string|null
*/
private $command;

public function __construct(Message $message, $topic, $command)
{
$this->message = $message;
$this->topic = $topic;
$this->command = $command;
}

/**
* @return Message
*/
public function getMessage()
{
return $this->message;
}

/**
* @return null|string
*/
public function getTopic()
{
return $this->topic;
}

/**
* @return null|string
*/
public function getCommand()
{
return $this->command;
}
}
60 changes: 60 additions & 0 deletions pkg/enqueue/Client/OnPrepareMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Enqueue\Client;

class OnPrepareMessage
{
/**
* @var string|array|Message|\JsonSerializable
*/
private $message;

/**
* @var string|null
*/
private $topic;

/**
* @var string|null
*/
private $command;

public function __construct($message, $topic, $command)
{
$this->message = $message;
$this->topic = $topic;
$this->command = $command;
}

/**
* @return array|Message|\JsonSerializable|string
*/
public function getMessage()
{
return $this->message;
}

/**
* @param array|Message|\JsonSerializable|string $message
*/
public function setMessage($message)
{
$this->message = $message;
}

/**
* @return null|string
*/
public function getTopic()
{
return $this->topic;
}

/**
* @return null|string
*/
public function getCommand()
{
return $this->command;
}
}
52 changes: 52 additions & 0 deletions pkg/enqueue/Client/OnSend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Enqueue\Client;

class OnSend
{
/**
* @var Message
*/
private $message;

/**
* @var string|null
*/
private $topic;

/**
* @var string|null
*/
private $command;

public function __construct(Message $message, $topic, $command)
{
$this->message = $message;
$this->topic = $topic;
$this->command = $command;
}

/**
* @return Message
*/
public function getMessage()
{
return $this->message;
}

/**
* @return null|string
*/
public function getTopic()
{
return $this->topic;
}

/**
* @return null|string
*/
public function getCommand()
{
return $this->command;
}
}
Loading