Skip to content

Commit 3d406cc

Browse files
committed
wamp
1 parent 49538de commit 3d406cc

File tree

5 files changed

+55
-2
lines changed

5 files changed

+55
-2
lines changed

docs/transport/wamp.md

+30
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ It uses internally Thruway PHP library [voryx/thruway](https://github.com/voryx/
88
* [Start the WAMP router](#start-the-wamp-router)
99
* [Create context](#create-context)
1010
* [Consume message](#consume-message)
11+
* [Subscription consumer](#subscription-consumer)
1112
* [Send message to topic](#send-message-to-topic)
1213

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

62+
## Subscription consumer
63+
64+
```php
65+
<?php
66+
use Interop\Queue\Message;
67+
use Interop\Queue\Consumer;
68+
69+
/** @var \Enqueue\Wamp\WampContext $context */
70+
/** @var \Enqueue\Wamp\WampDestination $fooQueue */
71+
/** @var \Enqueue\Wamp\WampDestination $barQueue */
72+
73+
$fooConsumer = $context->createConsumer($fooQueue);
74+
$barConsumer = $context->createConsumer($barQueue);
75+
76+
$subscriptionConsumer = $context->createSubscriptionConsumer();
77+
$subscriptionConsumer->subscribe($fooConsumer, function(Message $message, Consumer $consumer) {
78+
// process message
79+
80+
return true;
81+
});
82+
$subscriptionConsumer->subscribe($barConsumer, function(Message $message, Consumer $consumer) {
83+
// process message
84+
85+
return true;
86+
});
87+
88+
$subscriptionConsumer->consume(2000); // 2 sec
89+
```
90+
6191
## Send message to topic
6292

6393
```php

phpunit.xml.dist

+4
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@
104104
<testsuite name="dsn">
105105
<directory>pkg/dsn/Tests</directory>
106106
</testsuite>
107+
108+
<testsuite name="wamp transport">
109+
<directory>pkg/wamp/Tests</directory>
110+
</testsuite>
107111
</testsuites>
108112

109113
<php>

pkg/enqueue/Resources.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public static function getKnownConnections(): array
165165
'package' => 'enqueue/mongodb',
166166
];
167167
$map[WampConnectionFactory::class] = [
168-
'schemes' => ['wamp'],
168+
'schemes' => ['wamp', 'ws'],
169169
'supportedSchemeExtensions' => [],
170170
'package' => 'enqueue/wamp',
171171
];

pkg/enqueue/Tests/ResourcesTest.php

+19
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Enqueue\Redis\RedisConnectionFactory;
66
use Enqueue\Resources;
7+
use Enqueue\Wamp\WampConnectionFactory;
78
use Interop\Queue\ConnectionFactory;
89
use PHPUnit\Framework\TestCase;
910

@@ -127,4 +128,22 @@ public function testShouldAllowGetPreviouslyRegisteredConnection()
127128
$this->assertArrayHasKey('package', $connectionInfo);
128129
$this->assertSame('foo/bar', $connectionInfo['package']);
129130
}
131+
132+
public function testShouldHaveRegisteredWampConfiguration()
133+
{
134+
$availableConnections = Resources::getKnownConnections();
135+
136+
$this->assertInternalType('array', $availableConnections);
137+
$this->assertArrayHasKey(WampConnectionFactory::class, $availableConnections);
138+
139+
$connectionInfo = $availableConnections[WampConnectionFactory::class];
140+
$this->assertArrayHasKey('schemes', $connectionInfo);
141+
$this->assertSame(['wamp', 'ws'], $connectionInfo['schemes']);
142+
143+
$this->assertArrayHasKey('supportedSchemeExtensions', $connectionInfo);
144+
$this->assertSame([], $connectionInfo['supportedSchemeExtensions']);
145+
146+
$this->assertArrayHasKey('package', $connectionInfo);
147+
$this->assertSame('enqueue/wamp', $connectionInfo['package']);
148+
}
130149
}

pkg/wamp/WampConnectionFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private function parseDsn(string $dsn): array
9393
{
9494
$dsn = new Dsn($dsn);
9595

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

0 commit comments

Comments
 (0)