Skip to content

Commit

Permalink
wamp
Browse files Browse the repository at this point in the history
  • Loading branch information
ASKozienko committed Oct 23, 2018
1 parent c8af9e2 commit b8f0453
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bin/subtree-split
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ remote async-event-dispatcher [email protected]:php-enqueue/async-event-dispatcher.
remote async-command [email protected]:php-enqueue/async-command.git
remote mongodb [email protected]:php-enqueue/mongodb.git
remote dsn [email protected]:php-enqueue/dsn.git
remote wamp [email protected]:php-enqueue/wamp.git

split 'pkg/enqueue' enqueue
split 'pkg/simple-client' simple-client
Expand All @@ -90,3 +91,4 @@ split 'pkg/async-event-dispatcher' async-event-dispatcher
split 'pkg/async-command' async-command
split 'pkg/mongodb' mongodb
split 'pkg/dsn' dsn
split 'pkg/wamp' wamp
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- [Kafka](transport/kafka.md)
- [Stomp](transport/stomp.md)
- [Redis](transport/redis.md)
- [Wamp](transport/wamp.md)
- [Doctrine DBAL](transport/dbal.md)
- [Filesystem](transport/filesystem.md)
- [Null](transport/null.md)
Expand Down
73 changes: 73 additions & 0 deletions docs/transport/wamp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Web Application Messaging Protocol (WAMP) Transport

A transport for [Web Application Messaging Protocol](https://wamp-proto.org/).
WAMP is an open standard WebSocket subprotocol.
It uses internally Thruway PHP library [voryx/thruway](https://github.com/voryx/Thruway)

* [Installation](#installation)
* [Start the WAMP router](#start-the-wamp-router)
* [Create context](#create-context)
* [Consume message](#consume-message)
* [Send message to topic](#send-message-to-topic)

## Installation

```bash
$ composer require enqueue/wamp
```

## Start the WAMP router

```bash
$ php vendor/voryx/thruway/Examples/SimpleWsRouter.php
```

Thruway is now running on 127.0.0.1 port 9090


## Create context

```php
<?php
use Enqueue\Wamp\WampConnectionFactory;

$connectionFactory = new WampConnectionFactory();

$context = $connectionFactory->createContext();

// if you have enqueue/enqueue library installed you can use a factory to build context from DSN
$context = (new \Enqueue\ConnectionFactoryFactory())->create('wamp:')->createContext();
```

## Consume message:

Start message consumer before send message to the topic

```php
<?php
/** @var \Enqueue\Wamp\WampContext $context */

$fooTopic = $context->createTopic('foo');

$consumer = $context->createConsumer($fooQueue);

while (true) {
if ($message = $consumer->receive()) {
// process a message
}
}
```

## Send message to topic

```php
<?php
/** @var \Enqueue\Wamp\WampContext $context */

$fooTopic = $context->createTopic('foo');
$message = $context->createMessage('Hello world!');

$context->createProducer()->send($fooTopic, $message);
```

[back to index](../index.md)
6 changes: 6 additions & 0 deletions pkg/enqueue/Resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Enqueue\Redis\RedisConnectionFactory;
use Enqueue\Sqs\SqsConnectionFactory;
use Enqueue\Stomp\StompConnectionFactory;
use Enqueue\Wamp\WampConnectionFactory;
use Interop\Queue\ConnectionFactory;

final class Resources
Expand Down Expand Up @@ -163,6 +164,11 @@ public static function getKnownConnections(): array
'supportedSchemeExtensions' => [],
'package' => 'enqueue/mongodb',
];
$map[WampConnectionFactory::class] = [
'schemes' => ['wamp'],
'supportedSchemeExtensions' => [],
'package' => 'enqueue/wamp',
];

self::$knownConnections = $map;
}
Expand Down

0 comments on commit b8f0453

Please sign in to comment.