Important

You are browsing the documentation for version 3.1 of OroCommerce, OroCRM and OroPlatform, which is no longer maintained. Read version 5.1 (the latest LTS version) of the Oro documentation to get up-to-date information.

See our Release Process documentation for more information on the currently supported and upcoming releases.

Publish Messages to Existing Topics

Publish Messages from Backend

To publish to and read messages from WebSocket connections topics on the backend side of Oro application, OroSyncBundle provides a WebSocket oro_sync.websocket_client client which in is based on Gos WebSocketClient component GosComponentWebSocketClientWampClient.

WebSocket client makes use of authentication tickets mechanism, so you should not worry about authentication on the backend side.

Note

WebSocket client oro_sync.websocket_client uses anonymous authentication tickets, so when you connect to WebSocket server, it treats you as an anonymous.

You can publish messages to channels using the publish() method of the oro_sync.websocket_client, e.g.:

1$websocketClient = $this->get('oro_sync.websocket_client');
2$websocketClient->publish('oro/custom-channel', ['foo' => 'bar']);

It is strongly recommended to use the oro_sync.client.connection_checker connection checker before trying to connect or publish to websocket server, e.g.:

1$websocketConnectionChecker = $this->get('oro_sync.client.connection_checker');
2if ($websocketConnectionChecker->checkConnection()) {
3    $websocketClient = $this->get('oro_sync.websocket_client');
4    $websocketClient->publish('oro/custom-channel', ['foo' => 'bar']);
5}

Publish Messages from Frontend

At the moment there is no option to publish messages to websockets topics from the frontend side.

List All Declared Topics

All declared topics for WebSocket connections in your application (that you can subscribe and publish messages to) are declared in the websocket_routing.yml files in Resources/config/oro/ folders in application bundles. You can search all these files and look into them to find all declared topics.

Note

For more details on how to declare topics, see the Create Your Topic and Handler for Publishing and Subscribing topic.