-
Notifications
You must be signed in to change notification settings - Fork 0
Tips on return values (normalization)
Walter Dal Mut edited this page Jan 22, 2017
·
5 revisions
The response normalization is delegated to the user, your can create a
QueueProxy
to normalize responses
<?php
class QueueProxy extends Queue
{
public function receive($queueName, array $options)
{
list($receipt, $message) = parent::receive($queuename, $options);
// json normalization
return [$receipt, json_decode($message, true)];
}
}
Or if you have models you can use a serializer/deserializer (like
symfony/serializer
)
public function receive($queueName, array $options)
{
list($receipt, $message) = parent::receive($queuename, $options);
// returns ["receiptId", ItemCreated{}]
return [
$receipt,
$this->serializer->deserialize($message, ItemCreated::class, 'json')
];
}
Like responses normalization you can use the proxy also for the message normalization
<?php
class QueueProxy extends Queue
{
public function send($queueName, $message, array $options)
{
$adapterResponse = parent::send($queuename, $message, $options);
// every adapter reply with different response
$isSent = $this->normalizeAdapterResponse($adapterResponse);
return $isSent;
}
private function normalizeAdapterResponse($adapterResponse)
{
$isSent = /* check the adapter response [true/false or exceptions] */
return $isSent;
}
}
This project is sponsored by Corley SRL