-
-
Notifications
You must be signed in to change notification settings - Fork 289
AWS SQS implementation #192
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
Conversation
|
@elitemaks, signal helper is deprecated. Please, merge master into the patch and see beanstalk driver as example for updating. yii2-queue/src/drivers/beanstalk/Queue.php Lines 42 to 70 in b2754ec
yii2-queue/src/drivers/beanstalk/Command.php Lines 48 to 57 in b2754ec
yii2-queue/src/drivers/beanstalk/Command.php Lines 59 to 69 in b2754ec
Also, it should be covered with tests. |
|
@zhuravljov Thanks, already implemented correct "run" and "listen" methods, please check. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also consider ability to clear a queue and remove separate messages by ID in case this is possible.
yii2-queue/src/drivers/redis/Command.php
Lines 76 to 82 in f5ff542
| public function actionClear() | |
| { | |
| if ($this->confirm('Are you sure?')) { | |
| $this->queue->clear(); | |
| $this->stdout("Queue has been cleared.\n"); | |
| } | |
| } |
http://docs.aws.amazon.com/aws-sdk-php/v2/api/class-Aws.Sqs.SqsClient.html#_purgeQueue
src/drivers/sqs/Queue.php
Outdated
| } elseif (!$repeat) { | ||
| break; | ||
| } elseif ($delay) { | ||
| sleep($delay); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use long polling instead of sleep.
http://docs.aws.amazon.com/aws-sdk-php/v2/guide/service-sqs.html#receiving-messages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, please check. The limitation is that the max time long polling keeps the connection is 20 secs, so after that, the loop will be restarted. And, it works differently from "sleep" in a way, that if the message appears in a queue, it's handled without waiting for polling timeout.
| if ($payload = $this->getPayload()) { | ||
| list($ttr, $message) = explode(';', $payload['Body'], 2); | ||
| //reserve it so it is not visible to another worker till ttr | ||
| $this->reserve($payload, $ttr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use reserve inside getPayload.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about that. I think it's better to separate responsibility of these methods, as we can, for example, get payload and then delete the message, without the need of reserving it.
src/drivers/sqs/Queue.php
Outdated
| 'MessageBody' => "$ttr;$message", | ||
| ]); | ||
|
|
||
| if ($model === null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In which cases this->getClient()->sendMessage() can return null instead of array?
If this is possible, pushMessage must throw an exception, because it always returns message ID. Else the block should be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, due to the documentation it returns model only. Exceptions are raised in aws sdk methods. I removed If block.
|
@zhuravljov "clear" has been implemented. Unfortunately, as I got it, there is no way to delete a specific message by ID. We can only get the next message in a queue and delete it - I think it does not make sense. |
|
Unfortunately, it is not possible to retrieve or remove a message from the queue based on an ID. @zhuravljov This PR looks like it's good enough already. |
|
@thiagotalma still unit tests and documentation should be done. @zhuravljov I started with unit tests, please check the last commit. But I need some assistance - with SQS almost everything depends on AWS client, so I had to mock it. Not sure if this is the best way, and if I need to write tests for other functions, as there is no way to check a real queue. |
|
Created eng and rus docs for SQS queue driver. |
|
@samdark Hello Alex, please advise how to proceed with this PR as I did not get any reply form reviewers for a long time already. |
|
@zhuravljov That PR looks good enough already. |
|
@elitemaks would be nice to create tests with real connection to AWS, if possible. If not, it will without tests. |
|
@zhuravljov Thanks for the reply! it's possible, but this way "key" and "secret" for account access will be stored in the extension's code. I can create a test acc and use those credentials. Please let me know if that's ok, then I can do it. |
|
@zhuravljov The only way to include real AWS SQS account into tests is to put credentials to the config file. I think it's not correct to include creds in public repo. |
|
It is possible to create a secret env var on travis side, no one can see it once stored and only build run by owners can use them. enqueue/sqs is tested that way |
|
Ok but still, someone has to create that account on SQS. |
|
That should be done by repo owners. |
|
I would suggest to use ElasticMQ to mock SQS communication. |
Only one PurgeQueue operation is allowed every 60 seconds
|
Merged. Thank you! |
Continuing the work started by manoj-malviya - implementation of the queue based on Amazon SQS.
Currently, all commits by manoj-malviya are merged in this PR. I will continue to fix requests from old PR and glad to hear new feedbacks.