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

merged 13 commits into from
Oct 24, 2018

Conversation

ASKozienko
Copy link
Member

@ASKozienko ASKozienko commented Oct 22, 2018

Web Application Messaging Protocol (WAMP) Transport

A transport for Web Application Messaging Protocol.
WAMP is an open standard WebSocket subprotocol.
It uses internally Thruway PHP library voryx/thruway

Installation

$ composer require enqueue/wamp

Start the WAMP router

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

Thruway is now running on 127.0.0.1 port 9090

Create context

<?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
/** @var \Enqueue\Wamp\WampContext $context */

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

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

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

Subscription consumer

<?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
/** @var \Enqueue\Wamp\WampContext $context */

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

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

back to index

*/
public function acknowledge(Message $message): void
{
// do nothing. redis transport always works in auto ack mode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redis -> wamp

{
InvalidMessageException::assertMessageInstanceOf($message, WampMessage::class);

// do nothing on reject. redis transport always works in auto ack mode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

$this->redelivered = false;
}

public function jsonSerialize(): array
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you use a concept from rdkafka transport (with a serializer interface)?

pkg/wamp/LICENSE Outdated
@@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2017 Kotliar Maksym
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright (c) 2018 Forma-Pro

@@ -0,0 +1,27 @@
# Web Application Messaging Protocol Transport
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`# Web Application Messaging Protocol (WAMP) Transport


$this->client->getLoop()->run();

return $this->message ?: null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will have 100 clients in the context if we receive 100 message, right? Could we somehow reset them once a message has been received ?

@makasim
Copy link
Member

makasim commented Oct 22, 2018

Add docs, update readme.

@makasim
Copy link
Member

makasim commented Oct 23, 2018

@makasim
Copy link
Member

makasim commented Oct 23, 2018

@makasim
Copy link
Member

makasim commented Oct 23, 2018

resolve conflicts

@makasim
Copy link
Member

makasim commented Oct 23, 2018

{
$dsn = new Dsn($dsn);

if ('wamp' !== $dsn->getSchemeProtocol()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wamp and ws

@ASKozienko ASKozienko changed the title [WIP] WAMP WAMP Oct 23, 2018
@makasim makasim merged commit 11d1e3e into master Oct 24, 2018
@makasim makasim deleted the wamp branch October 24, 2018 06:37
ASKozienko pushed a commit that referenced this pull request Nov 2, 2018
@makasim makasim added this to the 0.9 milestone Nov 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants