Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 WebSocketBundle - ZMQ Push not working

I'm using Symfony2 to build a simple chat application. I decided to use the GeniusesOfSymfony/WebSocketBundle for my WebSocket, which is powered by Ratchet :

https://github.com/GeniusesOfSymfony/WebSocketBundle

I managed to get the chat working using PubSub, but I want to use the push integration instead: I want the client to send the message via AJAX to my Symfony2 controller, which in turn should push the message to all clients of the WebSocket.

I followed this documentation page:

https://github.com/GeniusesOfSymfony/WebSocketBundle/blob/master/Resources/docs/Pusher.md

I've tried using both ZMQ and Websocket Pusher.

With ZMQ, when I run the websocket, I get the cmd notification:

ZMQ transport listening on 127.0.0.1:5555

However, pushing messages doesn't work:

$pusher = $this->container->get("gos_web_socket.zmq.pusher");
//push(data, route_name, route_arguments)
$pusher->push(["type" => "newMessage", "text" => $request->request->get("msg")], "chat_topic");

This is the onPush method in my ChatTopic class:

class ChatTopic implements TopicInterface, PushableTopicInterface {

    public function onPush(Topic $topic, WampRequest $request, $data, $provider) {
        $topic->broadcast($data);
    }
}

The onPush method never gets called. Also, the pusher events never get fired. There doesn't appear to be an exception in the code.

With WebSocket Pusher, I'm not even able to get the service running. There is no notification in the cmd like with ZMQ, and using netstat command I was not able to detect that it's listening on port 1337. When I try to push to it, I get the exception :

Could not open socket. Reason: No connection could be made because the target machine actively refused it

Probably because there is no service listening on port 1337.

P.S. - I am on Windows 10 and using WAMP server. I've successfully installed the ZMQ extension on WAMP, as indicated in the phpinfo().

like image 567
Royar Avatar asked Nov 01 '16 23:11

Royar


1 Answers

The documentation you quoted, pusher.md, is not complete. You must also register your topic as a service and tag it as an available topic for the config.

It would be best to follow the TopicSetup.md. However, here is the missing highlight.

The new ChatTopic class can be registered in the Symfony Services AppBundle/Resources/config/services.yml and tagged like so:

services:
    app.chat_topic_service:
        class: App\AppBundle\Topic\ChatTopic
        tags:
            - { name: gos_web_socket.topic }
like image 190
Harmon Wood Avatar answered Nov 08 '22 14:11

Harmon Wood