FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Mongodb transport by turboboy88 · Pull Request #430 · php-enqueue/enqueue-dev · GitHub

Mongodb transport - #430

Merged
makasim merged 25 commits into
php-enqueue:masterfrom
turboboy88:mongodb_transport
May 3, 2018
Merged

Mongodb transport#430
makasim merged 25 commits into
php-enqueue:masterfrom
turboboy88:mongodb_transport

Conversation

turboboy88 commented Apr 26, 2018
edited by makasim
Loading

Copy link
Copy Markdown
Contributor

Mongodb transport (ref #284)

Comment thread docker-compose.yml Outdated
- RDKAFKA_PORT=9092
- PUBSUB_EMULATOR_HOST=http://google-pubsub:8085
- GCLOUD_PROJECT=mqdev
- MONGO_CONNECTION_STRING=mongodb://127.0.0.1/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

rename to MONGO_DSN

*/
private $driverOptions;

public function __construct($uri = 'mongodb://127.0.0.1/', array $config = [], array $uriOptions = [], array $driverOptions = [])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

constructor must accept one argument, an array.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

t should have uri, uriOptions, driverOptions keys and other options

Comment thread pkg/mongodb/MongodbConsumer.php Outdated
}

return $convertedMessage;
} catch (\Exception $e) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

no need for catch

Comment thread pkg/mongodb/MongodbConsumer.php Outdated
try {
$now = time();
$collection = $this->context->getCollection();
$message = $collection->findOne(['$or' => [['delayed_until' => ['$exists' => false]], ['delayed_until' => ['$lte' => $now]]]], ['sort' => ['priority' => -1]]);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

the line is too long, could you split it into several lines??

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Comment thread pkg/mongodb/MongodbConsumer.php Outdated
if (!$message) {
return null;
}
$mongodbMessage = $message->getArrayCopy();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Comment thread pkg/mongodb/MongodbConsumer.php Outdated
}

if ($mongodbMessage['properties']) {
$message->setProperties(JSON::decode($mongodbMessage['properties']));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

IMO there is no need to encode properties nor headers to json, we could store an array in mongodb.

Comment thread pkg/mongodb/MongodbConsumer.php Outdated
*/
protected function convertMessage(array $mongodbMessage)
{
$message = $this->context->createMessage();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

the createMessage method accept body, headers, and properties as arguments. pass them

/**
* @return array
*/
public function getConfig()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

let's not make it public for now.

Comment thread pkg/mongodb/MongodbProducer.php Outdated
$collection = $this->context->getCollection();
$collection->insertOne($mongoMessage);
} catch (\Exception $e) {
throw new Exception('The transport fails to send the message due to some internal error.', null, $e);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The transport has failed to send the message due to some internal error.

Comment thread pkg/mongodb/composer.json Outdated
"require": {
"php": ">=5.6",
"queue-interop/queue-interop": "^0.6@dev|^1.0.0-alpha1",
"php-http/client-common": "^1.7@dev",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I dont think we needed, please remove

turboboy88 changed the title initial commit Mongodb transport Apr 26, 2018
Comment thread composer.json Outdated
"empi89/php-amqp-stubs": "*@dev",
"php-http/client-common": "^1.7@dev"
"php-http/client-common": "^1.7@dev",
"mongodb/mongodb": "^1.3"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

could be remove as you required it in enqueue/mongodb

Comment thread docker-compose.yml Outdated
- RDKAFKA_PORT=9092
- PUBSUB_EMULATOR_HOST=http://google-pubsub:8085
- GCLOUD_PROJECT=mqdev
- MONGO_DSN=mongodb://127.0.0.1/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

should be mongodb://mongo/

Comment thread docker-compose.yml
mongo:
image: mongo
ports:
- "27017:27017"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

add an empty line after the service definition.

Comment thread pkg/mongodb/MongodbConsumer.php Outdated
{
$now = time();
$collection = $this->context->getCollection();
$message = $collection->findOneAndDelete(['$or' => [['delayed_until' => ['$exists' => false]], ['delayed_until' => ['$lte' => $now]]]],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

please split into several lines.

Comment thread pkg/mongodb/MongodbConsumer.php Outdated
protected function convertMessage(array $mongodbMessage)
{
$message = $this->context->createMessage($mongodbMessage['body'], $mongodbMessage['properties'], $mongodbMessage['headers']);
$message->setId($mongodbMessage['_id']->__toString());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

(string) $mongodbMessage['_id']

Comment thread pkg/mongodb/MongodbContext.php Outdated

public function getCollection()
{
return $this->client->selectDatabase($this->config['dbname'])->selectCollection($this->config['collection_name']);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
<?php

return $this->client
    ->selectDatabase($this->config['dbname'])
    ->selectCollection($this->config['collection_name'])
;

$mongoMessage = [
'published_at' => $publishedAt,
'body' => $body,
'headers' => JSON::encode($message->getHeaders()),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

no need to json encode

Comment thread pkg/mongodb/composer.json Outdated
"homepage": "https://enqueue.forma-pro.com/",
"license": "MIT",
"require": {
"php": ">=5.6",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

^7.1

*/
private $config;

public function __construct($config = 'mongodb:')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

could you please add a docblcok with the information on possible configuration options

$this->markTestSkipped('The MONGO_DSN env is not available. Skip tests');
}
$params = ['uri' => $env];
$factory = new MongodbConnectionFactory($params);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
<?php
$factory = new MongodbConnectionFactory(['uri' => $env]);

));
}

if ($parsedUrl['scheme'].':' === $dsn) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

hardcode string mongodb:


if ($parsedUrl['scheme'].':' === $dsn) {
return [
'uri' => $parsedUrl['scheme'].'://127.0.0.1/',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

same here

$config['uri'] = $parsedUrl['scheme'].'://'.$parsedUrl['host'];

if (isset($parsedUrl['path']) && '/' !== $parsedUrl['path']) {
$pathArr = explode('/', $parsedUrl['path']);

makasim Apr 27, 2018
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

rename the var to pathParts

];
}

$config['uri'] = $parsedUrl['scheme'].'://'.$parsedUrl['host'];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

this is not correct, the DSN might contain user, pasword, port, other options in it,

I think it would be good to store the orignal url as is is

}

if (isset($parsedUrl['query'])) {
parse_str($parsedUrl['query'], $queryParts);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

use of undefined var, define $queryParts = null just before this line

parse_str($parsedUrl['query'], $queryParts);

//get enqueue attributes values
if (isset($queryParts['polling_interval']) && !empty($queryParts['polling_interval'])) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

there is no need for isset()

$factory = new Definition(MongodbConnectionFactory::class);
$factory->setArguments([$config]);
} else {
throw new \LogicException('Set "dsn" options when you want ot use Mongodb.');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

instead of this add required to ->scalarNode('dsn')

{
if (false == empty($config['dsn'])) {
$factory = new Definition(MongodbConnectionFactory::class);
$factory->setArguments([$config]);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

as far as I remember Definition takes an array of arguments as a second constructor argument.

throw new \LogicException('The config must be either an array of options, a DSN string or null');
}
$config = array_replace([
'uri' => 'mongodb://127.0.0.1/',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think we should add dbname and a collection here as well

Comment thread pkg/mongodb/MongodbProducer.php Outdated
'headers' => $message->getHeaders(),
'properties' => $message->getProperties(),
'priority' => $message->getPriority(),
'queue' => $destination->getQueueName(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The use of getQueueName method is a bit misleading as we can send a message to the topic too.

Could you please add a neutral getName method to the destination and use it everywhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Added getName() alias for getQueueName() method. getQueueName() method should be implemented from PsrQueue interface.

$timeout /= 1000;
$startAt = microtime(true);

while (true) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

let's try capped collection plus tailable cursor approach.

https://gist.github.com/ASKozienko/cf45b09c68774ed83dea67b6d02d5846

Comment thread pkg/mongodb/MongodbProducer.php Outdated
InvalidDestinationException::assertDestinationInstanceOf($destination, MongodbDestination::class);
InvalidMessageException::assertMessageInstanceOf($message, MongodbMessage::class);

if (null !== $this->priority && 0 === $message->getPriority()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

should be if (null !== $this->priority && null === $message->getPriority()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

and set priority in the message to null by default (just unset).

makasim merged commit ccaaeb1 into php-enqueue:master May 3, 2018
ASKozienko pushed a commit that referenced this pull request Nov 2, 2018
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL