Skip to content

Message serialization. #846

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 12 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"ext-mongodb": "^1.3",
"ext-rdkafka": "^3.0.3",

"queue-interop/amqp-interop": "^0.8",
"queue-interop/queue-interop": "^0.7|^0.8",
"queue-interop/amqp-interop": "dev-master",
"queue-interop/queue-interop": "dev-master",
"bunny/bunny": "^0.2.4|^0.3|^0.4",
"php-amqplib/php-amqplib": "^2.7",
"doctrine/dbal": "^2.6",
Expand Down Expand Up @@ -55,6 +55,16 @@
"kwn/php-rdkafka-stubs": "^1.0.2",
"friendsofphp/php-cs-fixer": "^2"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/Sevavietl/queue-interop"
},
{
"type": "vcs",
"url": "https://github.com/Sevavietl/amqp-interop"
}
],
"autoload": {
"psr-4": {
"Enqueue\\AmqpBunny\\": "pkg/amqp-bunny/",
Expand Down
4 changes: 3 additions & 1 deletion pkg/amqp-bunny/AmqpContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ public function __construct($bunnyChannel, array $config)
}

/**
* @param mixed $body
*
* @return InteropAmqpMessage
*/
public function createMessage(string $body = '', array $properties = [], array $headers = []): Message
public function createMessage($body = '', array $properties = [], array $headers = []): Message
{
return new AmqpMessage($body, $properties, $headers);
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/amqp-ext/AmqpContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ public function __construct($extChannel)
}

/**
* @param mixed $body
*
* @return InteropAmqpMessage
*/
public function createMessage(string $body = '', array $properties = [], array $headers = []): Message
public function createMessage($body = '', array $properties = [], array $headers = []): Message
{
return new AmqpMessage($body, $properties, $headers);
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/amqp-lib/AmqpContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ public function __construct(AbstractConnection $connection, array $config)
}

/**
* @param mixed $body
*
* @return InteropAmqpMessage
*/
public function createMessage(string $body = '', array $properties = [], array $headers = []): Message
public function createMessage($body = '', array $properties = [], array $headers = []): Message
{
return new AmqpMessage($body, $properties, $headers);
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dbal/DbalContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function __construct($connection, array $config = [])
/**
* {@inheritdoc}
*/
public function createMessage(string $body = '', array $properties = [], array $headers = []): Message
public function createMessage($body = '', array $properties = [], array $headers = []): Message
{
$message = new DbalMessage();
$message->setBody($body);
Expand Down
16 changes: 2 additions & 14 deletions pkg/dbal/DbalMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@

namespace Enqueue\Dbal;

use Interop\Queue\Impl\StringBodyOnlyTrait;
use Interop\Queue\Message;

class DbalMessage implements Message
{
/**
* @var string
*/
private $body;
use StringBodyOnlyTrait;

/**
* @var array
Expand Down Expand Up @@ -84,16 +82,6 @@ public function __construct(string $body = '', array $properties = [], array $he
$this->redeliverAfter = null;
}

public function setBody(string $body): void
{
$this->body = $body;
}

public function getBody(): string
{
return $this->body;
}

public function setProperties(array $properties): void
{
$this->properties = $properties;
Expand Down
4 changes: 1 addition & 3 deletions pkg/dbal/DbalProducer.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ public function send(Destination $destination, Message $message): void
$message->setTimeToLive($this->timeToLive);
}

$body = $message->getBody();

$publishedAt = null !== $message->getPublishedAt() ?
$message->getPublishedAt() :
(int) (microtime(true) * 10000)
Expand All @@ -72,7 +70,7 @@ public function send(Destination $destination, Message $message): void
$dbalMessage = [
'id' => Uuid::uuid4(),
'published_at' => $publishedAt,
'body' => $body,
'body' => $message->getBody(),
'headers' => JSON::encode($message->getHeaders()),
'properties' => JSON::encode($message->getProperties()),
'priority' => -1 * $message->getPriority(),
Expand Down
4 changes: 2 additions & 2 deletions pkg/dbal/Tests/DbalConsumerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ private function createConectionMock()

class InvalidMessage implements Message
{
public function getBody(): string
public function getBody()
{
}

public function setBody(string $body): void
public function setBody($body): void
{
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/fs/FsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ public function __construct(string $storeDir, int $preFetchCount, int $chmod, in
}

/**
* @param mixed $body
*
* @return FsMessage
*/
public function createMessage(string $body = '', array $properties = [], array $headers = []): Message
public function createMessage($body = '', array $properties = [], array $headers = []): Message
{
return new FsMessage($body, $properties, $headers);
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/fs/FsMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class FsMessage implements Message, \JsonSerializable
{
/**
* @var string
* @var string|int|float|array|\JsonSerializable
*/
private $body;

Expand All @@ -28,20 +28,20 @@ class FsMessage implements Message, \JsonSerializable
*/
private $redelivered;

public function __construct(string $body = '', array $properties = [], array $headers = [])
public function __construct($body = '', array $properties = [], array $headers = [])
{
$this->body = $body;
$this->properties = $properties;
$this->headers = $headers;
$this->redelivered = false;
}

public function setBody(string $body): void
public function setBody($body): void
{
$this->body = $body;
}

public function getBody(): string
public function getBody()
{
return $this->body;
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/gearman/GearmanContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ public function __construct(array $config)
}

/**
* @param mixed $body
*
* @return GearmanMessage
*/
public function createMessage(string $body = '', array $properties = [], array $headers = []): Message
public function createMessage($body = '', array $properties = [], array $headers = []): Message
{
return new GearmanMessage($body, $properties, $headers);
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/gearman/GearmanMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class GearmanMessage implements Message, \JsonSerializable
{
/**
* @var string
* @var string|int|float|array|\JsonSerializable
*/
private $body;

Expand All @@ -33,20 +33,20 @@ class GearmanMessage implements Message, \JsonSerializable
*/
private $job;

public function __construct(string $body = '', array $properties = [], array $headers = [])
public function __construct($body = '', array $properties = [], array $headers = [])
{
$this->body = $body;
$this->properties = $properties;
$this->headers = $headers;
$this->redelivered = false;
}

public function setBody(string $body): void
public function setBody($body): void
{
$this->body = $body;
}

public function getBody(): string
public function getBody()
{
return $this->body;
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/gps/GpsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ public function __construct($client, array $options = [])
}

/**
* @param mixed $body
*
* @return GpsMessage
*/
public function createMessage(string $body = '', array $properties = [], array $headers = []): Message
public function createMessage($body = '', array $properties = [], array $headers = []): Message
{
return new GpsMessage($body, $properties, $headers);
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/gps/GpsMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class GpsMessage implements Message, \JsonSerializable
{
/**
* @var string
* @var string|int|float|array|\JsonSerializable
*/
private $body;

Expand All @@ -34,7 +34,7 @@ class GpsMessage implements Message, \JsonSerializable
*/
private $nativeMessage;

public function __construct(string $body = '', array $properties = [], array $headers = [])
public function __construct($body = '', array $properties = [], array $headers = [])
{
$this->body = $body;
$this->properties = $properties;
Expand All @@ -43,12 +43,12 @@ public function __construct(string $body = '', array $properties = [], array $he
$this->redelivered = false;
}

public function getBody(): string
public function getBody()
{
return $this->body;
}

public function setBody(string $body): void
public function setBody($body): void
{
$this->body = $body;
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/mongodb/MongodbContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ public function __construct($client, array $config = [])
}

/**
* @param mixed $body
*
* @return MongodbMessage
*/
public function createMessage(string $body = '', array $properties = [], array $headers = []): Message
public function createMessage($body = '', array $properties = [], array $headers = []): Message
{
$message = new MongodbMessage();
$message->setBody($body);
Expand Down
18 changes: 3 additions & 15 deletions pkg/mongodb/MongodbMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@

namespace Enqueue\Mongodb;

use Interop\Queue\Impl\StringBodyOnlyTrait;
use Interop\Queue\Message;

class MongodbMessage implements Message
{
/**
* @var string
*/
private $id;
use StringBodyOnlyTrait;

/**
* @var string
*/
private $body;
private $id;

/**
* @var array
Expand Down Expand Up @@ -75,16 +73,6 @@ public function getId(): ?string
return $this->id;
}

public function setBody(string $body): void
{
$this->body = $body;
}

public function getBody(): string
{
return $this->body;
}

public function setProperties(array $properties): void
{
$this->properties = $properties;
Expand Down
4 changes: 1 addition & 3 deletions pkg/mongodb/MongodbProducer.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,14 @@ public function send(Destination $destination, Message $message): void
$message->setTimeToLive($this->timeToLive);
}

$body = $message->getBody();

$publishedAt = null !== $message->getPublishedAt() ?
$message->getPublishedAt() :
(int) (microtime(true) * 10000)
;

$mongoMessage = [
'published_at' => $publishedAt,
'body' => $body,
'body' => $message->getBody(),
'headers' => JSON::encode($message->getHeaders()),
'properties' => JSON::encode($message->getProperties()),
'priority' => $message->getPriority(),
Expand Down
4 changes: 2 additions & 2 deletions pkg/mongodb/Tests/MongodbConsumerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ private function createContextMock()

class InvalidMessage implements Message
{
public function getBody(): string
public function getBody()
{
}

public function setBody(string $body): void
public function setBody($body): void
{
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/null/NullContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
class NullContext implements Context
{
/**
* @param mixed $body
*
* @return NullMessage
*/
public function createMessage(string $body = '', array $properties = [], array $headers = []): Message
public function createMessage($body = '', array $properties = [], array $headers = []): Message
{
$message = new NullMessage();
$message->setBody($body);
Expand Down
2 changes: 1 addition & 1 deletion pkg/null/NullMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(string $body = '', array $properties = [], array $he
$this->redelivered = false;
}

public function setBody(string $body): void
public function setBody($body): void
{
$this->body = $body;
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/pheanstalk/PheanstalkContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ public function __construct(Pheanstalk $pheanstalk)
}

/**
* @param mixed $body
*
* @return PheanstalkMessage
*/
public function createMessage(string $body = '', array $properties = [], array $headers = []): Message
public function createMessage($body = '', array $properties = [], array $headers = []): Message
{
return new PheanstalkMessage($body, $properties, $headers);
}
Expand Down
Loading