From b8f0453bcbb2b6ea90fd1a79d7b68a54ef5e9099 Mon Sep 17 00:00:00 2001 From: Alexander Kozienko Date: Tue, 23 Oct 2018 10:37:11 +0300 Subject: [PATCH] wamp --- bin/subtree-split | 2 ++ docs/index.md | 1 + docs/transport/wamp.md | 73 +++++++++++++++++++++++++++++++++++++++ pkg/enqueue/Resources.php | 6 ++++ 4 files changed, 82 insertions(+) create mode 100644 docs/transport/wamp.md diff --git a/bin/subtree-split b/bin/subtree-split index 222574f13..f7d63eb34 100755 --- a/bin/subtree-split +++ b/bin/subtree-split @@ -66,6 +66,7 @@ remote async-event-dispatcher git@github.com:php-enqueue/async-event-dispatcher. remote async-command git@github.com:php-enqueue/async-command.git remote mongodb git@github.com:php-enqueue/mongodb.git remote dsn git@github.com:php-enqueue/dsn.git +remote wamp git@github.com:php-enqueue/wamp.git split 'pkg/enqueue' enqueue split 'pkg/simple-client' simple-client @@ -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 diff --git a/docs/index.md b/docs/index.md index 32580b53a..fe57d473f 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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) diff --git a/docs/transport/wamp.md b/docs/transport/wamp.md new file mode 100644 index 000000000..b94add54a --- /dev/null +++ b/docs/transport/wamp.md @@ -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 +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 +createTopic('foo'); + +$consumer = $context->createConsumer($fooQueue); + +while (true) { + if ($message = $consumer->receive()) { + // process a message + } +} +``` + +## Send message to topic + +```php +createTopic('foo'); +$message = $context->createMessage('Hello world!'); + +$context->createProducer()->send($fooTopic, $message); +``` + +[back to index](../index.md) \ No newline at end of file diff --git a/pkg/enqueue/Resources.php b/pkg/enqueue/Resources.php index 21172c636..3232ba013 100644 --- a/pkg/enqueue/Resources.php +++ b/pkg/enqueue/Resources.php @@ -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 @@ -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; }