Skip to content
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

WAMP #573

Merged
merged 13 commits into from
Oct 24, 2018
Merged

WAMP #573

Changes from 1 commit
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
30 changes: 30 additions & 0 deletions docs/transport/wamp.md
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ It uses internally Thruway PHP library [voryx/thruway](https://github.com/voryx/
* [Start the WAMP router](#start-the-wamp-router)
* [Create context](#create-context)
* [Consume message](#consume-message)
* [Subscription consumer](#subscription-consumer)
* [Send message to topic](#send-message-to-topic)

## Installation
@@ -58,6 +59,35 @@ while (true) {
}
```

## Subscription consumer

```php
<?php
use Interop\Queue\Message;
use Interop\Queue\Consumer;

/** @var \Enqueue\Wamp\WampContext $context */
/** @var \Enqueue\Wamp\WampDestination $fooQueue */
/** @var \Enqueue\Wamp\WampDestination $barQueue */

$fooConsumer = $context->createConsumer($fooQueue);
$barConsumer = $context->createConsumer($barQueue);

$subscriptionConsumer = $context->createSubscriptionConsumer();
$subscriptionConsumer->subscribe($fooConsumer, function(Message $message, Consumer $consumer) {
// process message

return true;
});
$subscriptionConsumer->subscribe($barConsumer, function(Message $message, Consumer $consumer) {
// process message

return true;
});

$subscriptionConsumer->consume(2000); // 2 sec
```

## Send message to topic

```php
4 changes: 4 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -104,6 +104,10 @@
<testsuite name="dsn">
<directory>pkg/dsn/Tests</directory>
</testsuite>

<testsuite name="wamp transport">
<directory>pkg/wamp/Tests</directory>
</testsuite>
</testsuites>

<php>
2 changes: 1 addition & 1 deletion pkg/enqueue/Resources.php
Original file line number Diff line number Diff line change
@@ -165,7 +165,7 @@ public static function getKnownConnections(): array
'package' => 'enqueue/mongodb',
];
$map[WampConnectionFactory::class] = [
'schemes' => ['wamp'],
'schemes' => ['wamp', 'ws'],
'supportedSchemeExtensions' => [],
'package' => 'enqueue/wamp',
];
19 changes: 19 additions & 0 deletions pkg/enqueue/Tests/ResourcesTest.php
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@

use Enqueue\Redis\RedisConnectionFactory;
use Enqueue\Resources;
use Enqueue\Wamp\WampConnectionFactory;
use Interop\Queue\ConnectionFactory;
use PHPUnit\Framework\TestCase;

@@ -127,4 +128,22 @@ public function testShouldAllowGetPreviouslyRegisteredConnection()
$this->assertArrayHasKey('package', $connectionInfo);
$this->assertSame('foo/bar', $connectionInfo['package']);
}

public function testShouldHaveRegisteredWampConfiguration()
{
$availableConnections = Resources::getKnownConnections();

$this->assertInternalType('array', $availableConnections);
$this->assertArrayHasKey(WampConnectionFactory::class, $availableConnections);

$connectionInfo = $availableConnections[WampConnectionFactory::class];
$this->assertArrayHasKey('schemes', $connectionInfo);
$this->assertSame(['wamp', 'ws'], $connectionInfo['schemes']);

$this->assertArrayHasKey('supportedSchemeExtensions', $connectionInfo);
$this->assertSame([], $connectionInfo['supportedSchemeExtensions']);

$this->assertArrayHasKey('package', $connectionInfo);
$this->assertSame('enqueue/wamp', $connectionInfo['package']);
}
}
2 changes: 1 addition & 1 deletion pkg/wamp/WampConnectionFactory.php
Original file line number Diff line number Diff line change
@@ -93,7 +93,7 @@ private function parseDsn(string $dsn): array
{
$dsn = new Dsn($dsn);

if ('wamp' !== $dsn->getSchemeProtocol()) {
if (false === in_array($dsn->getSchemeProtocol(), ['wamp', 'ws'], true)) {
throw new \LogicException(sprintf(
'The given scheme protocol "%s" is not supported. It must be "wamp"',
$dsn->getSchemeProtocol()