Skip to content

Commit b8f0453

Browse files
committed
wamp
1 parent c8af9e2 commit b8f0453

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed

bin/subtree-split

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ remote async-event-dispatcher [email protected]:php-enqueue/async-event-dispatcher.
6666
remote async-command [email protected]:php-enqueue/async-command.git
6767
remote mongodb [email protected]:php-enqueue/mongodb.git
6868
remote dsn [email protected]:php-enqueue/dsn.git
69+
remote wamp [email protected]:php-enqueue/wamp.git
6970

7071
split 'pkg/enqueue' enqueue
7172
split 'pkg/simple-client' simple-client
@@ -90,3 +91,4 @@ split 'pkg/async-event-dispatcher' async-event-dispatcher
9091
split 'pkg/async-command' async-command
9192
split 'pkg/mongodb' mongodb
9293
split 'pkg/dsn' dsn
94+
split 'pkg/wamp' wamp

docs/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- [Kafka](transport/kafka.md)
1111
- [Stomp](transport/stomp.md)
1212
- [Redis](transport/redis.md)
13+
- [Wamp](transport/wamp.md)
1314
- [Doctrine DBAL](transport/dbal.md)
1415
- [Filesystem](transport/filesystem.md)
1516
- [Null](transport/null.md)

docs/transport/wamp.md

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Web Application Messaging Protocol (WAMP) Transport
2+
3+
A transport for [Web Application Messaging Protocol](https://wamp-proto.org/).
4+
WAMP is an open standard WebSocket subprotocol.
5+
It uses internally Thruway PHP library [voryx/thruway](https://github.com/voryx/Thruway)
6+
7+
* [Installation](#installation)
8+
* [Start the WAMP router](#start-the-wamp-router)
9+
* [Create context](#create-context)
10+
* [Consume message](#consume-message)
11+
* [Send message to topic](#send-message-to-topic)
12+
13+
## Installation
14+
15+
```bash
16+
$ composer require enqueue/wamp
17+
```
18+
19+
## Start the WAMP router
20+
21+
```bash
22+
$ php vendor/voryx/thruway/Examples/SimpleWsRouter.php
23+
```
24+
25+
Thruway is now running on 127.0.0.1 port 9090
26+
27+
28+
## Create context
29+
30+
```php
31+
<?php
32+
use Enqueue\Wamp\WampConnectionFactory;
33+
34+
$connectionFactory = new WampConnectionFactory();
35+
36+
$context = $connectionFactory->createContext();
37+
38+
// if you have enqueue/enqueue library installed you can use a factory to build context from DSN
39+
$context = (new \Enqueue\ConnectionFactoryFactory())->create('wamp:')->createContext();
40+
```
41+
42+
## Consume message:
43+
44+
Start message consumer before send message to the topic
45+
46+
```php
47+
<?php
48+
/** @var \Enqueue\Wamp\WampContext $context */
49+
50+
$fooTopic = $context->createTopic('foo');
51+
52+
$consumer = $context->createConsumer($fooQueue);
53+
54+
while (true) {
55+
if ($message = $consumer->receive()) {
56+
// process a message
57+
}
58+
}
59+
```
60+
61+
## Send message to topic
62+
63+
```php
64+
<?php
65+
/** @var \Enqueue\Wamp\WampContext $context */
66+
67+
$fooTopic = $context->createTopic('foo');
68+
$message = $context->createMessage('Hello world!');
69+
70+
$context->createProducer()->send($fooTopic, $message);
71+
```
72+
73+
[back to index](../index.md)

pkg/enqueue/Resources.php

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Enqueue\Redis\RedisConnectionFactory;
1717
use Enqueue\Sqs\SqsConnectionFactory;
1818
use Enqueue\Stomp\StompConnectionFactory;
19+
use Enqueue\Wamp\WampConnectionFactory;
1920
use Interop\Queue\ConnectionFactory;
2021

2122
final class Resources
@@ -163,6 +164,11 @@ public static function getKnownConnections(): array
163164
'supportedSchemeExtensions' => [],
164165
'package' => 'enqueue/mongodb',
165166
];
167+
$map[WampConnectionFactory::class] = [
168+
'schemes' => ['wamp'],
169+
'supportedSchemeExtensions' => [],
170+
'package' => 'enqueue/wamp',
171+
];
166172

167173
self::$knownConnections = $map;
168174
}

0 commit comments

Comments
 (0)