-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Messenger] Add Beanstalkd bridge #36582
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
3 changes: 3 additions & 0 deletions
3
src/Symfony/Component/Messenger/Bridge/Beanstalkd/.gitattributes
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/Tests export-ignore | ||
/phpunit.xml.dist export-ignore | ||
/.gitignore export-ignore |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
vendor/ | ||
composer.lock | ||
phpunit.xml |
7 changes: 7 additions & 0 deletions
7
src/Symfony/Component/Messenger/Bridge/Beanstalkd/CHANGELOG.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CHANGELOG | ||
========= | ||
|
||
5.2.0 | ||
----- | ||
|
||
* Introduced the Beanstalkd bridge. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2018-2020 Fabien Potencier | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is furnished | ||
to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
14 changes: 14 additions & 0 deletions
14
src/Symfony/Component/Messenger/Bridge/Beanstalkd/README.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Beanstalkd Messenger | ||
==================== | ||
|
||
Provides Beanstalkd integration for Symfony Messenger. | ||
|
||
Full DSN with options: `beanstalkd://<ip>:<port>?tube_name=<name>&timeout=<timeoutInSeconds>&ttr=<ttrInSeconds>` | ||
|
||
Resources | ||
--------- | ||
|
||
* [Contributing](https://symfony.com/doc/current/contributing/index.html) | ||
* [Report issues](https://github.com/symfony/symfony/issues) and | ||
[send Pull Requests](https://github.com/symfony/symfony/pulls) | ||
in the [main Symfony repository](https://github.com/symfony/symfony) |
18 changes: 18 additions & 0 deletions
18
src/Symfony/Component/Messenger/Bridge/Beanstalkd/Tests/Fixtures/DummyMessage.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Symfony\Component\Messenger\Bridge\Beanstalkd\Tests\Fixtures; | ||
|
||
class DummyMessage | ||
{ | ||
private $message; | ||
|
||
public function __construct(string $message) | ||
{ | ||
$this->message = $message; | ||
} | ||
|
||
public function getMessage(): string | ||
{ | ||
return $this->message; | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
src/Symfony/Component/Messenger/Bridge/Beanstalkd/Tests/Transport/BeanstalkdReceiverTest.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Messenger\Bridge\Beanstalkd\Tests\Transport; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Messenger\Bridge\Beanstalkd\Tests\Fixtures\DummyMessage; | ||
use Symfony\Component\Messenger\Bridge\Beanstalkd\Transport\BeanstalkdReceivedStamp; | ||
use Symfony\Component\Messenger\Bridge\Beanstalkd\Transport\BeanstalkdReceiver; | ||
use Symfony\Component\Messenger\Bridge\Beanstalkd\Transport\Connection; | ||
use Symfony\Component\Messenger\Exception\MessageDecodingFailedException; | ||
use Symfony\Component\Messenger\Transport\Serialization\PhpSerializer; | ||
use Symfony\Component\Messenger\Transport\Serialization\Serializer; | ||
use Symfony\Component\Serializer as SerializerComponent; | ||
use Symfony\Component\Serializer\Encoder\JsonEncoder; | ||
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; | ||
|
||
final class BeanstalkdReceiverTest extends TestCase | ||
{ | ||
public function testItReturnsTheDecodedMessageToTheHandler() | ||
{ | ||
$serializer = $this->createSerializer(); | ||
|
||
$tube = 'foo bar'; | ||
|
||
$beanstalkdEnvelope = $this->createBeanstalkdEnvelope(); | ||
$connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock(); | ||
$connection->expects($this->once())->method('get')->willReturn($beanstalkdEnvelope); | ||
$connection->expects($this->once())->method('getTube')->willReturn($tube); | ||
|
||
$receiver = new BeanstalkdReceiver($connection, $serializer); | ||
$actualEnvelopes = $receiver->get(); | ||
$this->assertCount(1, $actualEnvelopes); | ||
$this->assertEquals(new DummyMessage('Hi'), $actualEnvelopes[0]->getMessage()); | ||
|
||
/** @var BeanstalkdReceivedStamp $receivedStamp */ | ||
$receivedStamp = $actualEnvelopes[0]->last(BeanstalkdReceivedStamp::class); | ||
|
||
$this->assertInstanceOf(BeanstalkdReceivedStamp::class, $receivedStamp); | ||
$this->assertSame('1', $receivedStamp->getId()); | ||
$this->assertSame($tube, $receivedStamp->getTube()); | ||
} | ||
|
||
public function testItReturnsEmptyArrayIfThereAreNoMessages() | ||
{ | ||
$serializer = $this->createSerializer(); | ||
|
||
$connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock(); | ||
$connection->expects($this->once())->method('get')->willReturn(null); | ||
|
||
$receiver = new BeanstalkdReceiver($connection, $serializer); | ||
$actualEnvelopes = $receiver->get(); | ||
$this->assertIsArray($actualEnvelopes); | ||
$this->assertCount(0, $actualEnvelopes); | ||
} | ||
|
||
public function testItRejectTheMessageIfThereIsAMessageDecodingFailedException() | ||
{ | ||
$this->expectException(MessageDecodingFailedException::class); | ||
|
||
$serializer = $this->createMock(PhpSerializer::class); | ||
$serializer->expects($this->once())->method('decode')->willThrowException(new MessageDecodingFailedException()); | ||
|
||
$beanstalkdEnvelope = $this->createBeanstalkdEnvelope(); | ||
$connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock(); | ||
$connection->expects($this->once())->method('get')->willReturn($beanstalkdEnvelope); | ||
$connection->expects($this->once())->method('reject'); | ||
|
||
$receiver = new BeanstalkdReceiver($connection, $serializer); | ||
$receiver->get(); | ||
} | ||
|
||
private function createBeanstalkdEnvelope(): array | ||
{ | ||
return [ | ||
'id' => '1', | ||
'body' => '{"message": "Hi"}', | ||
'headers' => [ | ||
'type' => DummyMessage::class, | ||
], | ||
]; | ||
} | ||
|
||
private function createSerializer(): Serializer | ||
{ | ||
$serializer = new Serializer( | ||
new SerializerComponent\Serializer([new ObjectNormalizer()], ['json' => new JsonEncoder()]) | ||
); | ||
|
||
return $serializer; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/Symfony/Component/Messenger/Bridge/Beanstalkd/Tests/Transport/BeanstalkdSenderTest.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Messenger\Bridge\Beanstalkd\Tests\Transport; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Messenger\Bridge\Beanstalkd\Tests\Fixtures\DummyMessage; | ||
use Symfony\Component\Messenger\Bridge\Beanstalkd\Transport\BeanstalkdSender; | ||
use Symfony\Component\Messenger\Bridge\Beanstalkd\Transport\Connection; | ||
use Symfony\Component\Messenger\Envelope; | ||
use Symfony\Component\Messenger\Stamp\DelayStamp; | ||
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface; | ||
|
||
final class BeanstalkdSenderTest extends TestCase | ||
{ | ||
public function testSend() | ||
{ | ||
$envelope = new Envelope(new DummyMessage('Oy')); | ||
$encoded = ['body' => '...', 'headers' => ['type' => DummyMessage::class]]; | ||
|
||
$connection = $this->getMockBuilder(Connection::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$connection->expects($this->once())->method('send')->with($encoded['body'], $encoded['headers'], 0); | ||
|
||
$serializer = $this->getMockBuilder(SerializerInterface::class)->getMock(); | ||
$serializer->method('encode')->with($envelope)->willReturnOnConsecutiveCalls($encoded); | ||
|
||
$sender = new BeanstalkdSender($connection, $serializer); | ||
$sender->send($envelope); | ||
} | ||
|
||
public function testSendWithDelay() | ||
{ | ||
$envelope = (new Envelope(new DummyMessage('Oy')))->with(new DelayStamp(500)); | ||
$encoded = ['body' => '...', 'headers' => ['type' => DummyMessage::class]]; | ||
|
||
$connection = $this->createMock(Connection::class); | ||
$connection->expects($this->once())->method('send')->with($encoded['body'], $encoded['headers'], 500); | ||
|
||
$serializer = $this->createMock(SerializerInterface::class); | ||
$serializer->method('encode')->with($envelope)->willReturnOnConsecutiveCalls($encoded); | ||
|
||
$sender = new BeanstalkdSender($connection, $serializer); | ||
$sender->send($envelope); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
.../Component/Messenger/Bridge/Beanstalkd/Tests/Transport/BeanstalkdTransportFactoryTest.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Messenger\Bridge\Beanstalkd\Tests\Transport; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Messenger\Bridge\Beanstalkd\Transport\BeanstalkdTransport; | ||
use Symfony\Component\Messenger\Bridge\Beanstalkd\Transport\BeanstalkdTransportFactory; | ||
use Symfony\Component\Messenger\Bridge\Beanstalkd\Transport\Connection; | ||
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface; | ||
|
||
final class BeanstalkdTransportFactoryTest extends TestCase | ||
{ | ||
public function testSupports() | ||
{ | ||
$factory = new BeanstalkdTransportFactory(); | ||
|
||
$this->assertTrue($factory->supports('beanstalkd://127.0.0.1', [])); | ||
$this->assertFalse($factory->supports('doctrine://127.0.0.1', [])); | ||
} | ||
|
||
public function testCreateTransport() | ||
{ | ||
$factory = new BeanstalkdTransportFactory(); | ||
$serializer = $this->createMock(SerializerInterface::class); | ||
|
||
$this->assertEquals( | ||
new BeanstalkdTransport(Connection::fromDsn('beanstalkd://127.0.0.1'), $serializer), | ||
$factory->createTransport('beanstalkd://127.0.0.1', [], $serializer) | ||
); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.