GithubHelp home page GithubHelp logo

roadrunner-php / broadcast Goto Github PK

View Code? Open in Web Editor NEW
11.0 9.0 1.0 7.12 MB

:electric_plug: RoadRunner Broadcast SDK

Home Page: https://roadrunner.dev

License: MIT License

PHP 100.00%
php7 spiral pubsub websocket roadrunner

broadcast's Introduction

RoadRunner Broadcast Plugin Bridge

Latest Stable Version Build Status Codecov

This repository contains the codebase bridge for broadcast RoadRunner plugin.

Installation

To install application server and broadcast codebase

$ composer require spiral/roadrunner-broadcast

You can use the convenient installer to download the latest available compatible version of RoadRunner assembly:

$ composer require spiral/roadrunner-cli --dev
$ vendor/bin/rr get

Usage

For example, such a configuration would be quite feasible to run:

rpc:
  listen: tcp://127.0.0.1:6001

server:
  # Don't forget to create a "worker.php" file
  command: "php worker.php" 
  relay: "pipes"

http:
  address: 127.0.0.1:80
  # Indicate that HTTP support ws protocol
  middleware: [ "websockets" ]

websockets:
    broker: default
    path: "/ws"

broadcast:
    default:
        driver: memory
        config: {}

Read more about all available brokers on the documentation page.

After configuring and starting the RoadRunner server, the corresponding API will become available to you.

<?php

use Spiral\Goridge\RPC\RPC;
use Spiral\RoadRunner\Broadcast\Broadcast;

require __DIR__ . '/vendor/autoload.php';

$broadcast = new Broadcast(RPC::create('tcp://127.0.0.1:6001'));

//
// Now we can send a message to a specific topic
//
$broadcast->publish('channel-1', 'message for channel #1');

Select Specific Topic

Alternatively, you can also use a specific topic (or set of topics) as a separate entity and post directly to it.

// Now we can select the topic we need to work only with it
$topic = $broadcast->join(['channel-1', 'channel-2']);

// And send messages there
$topic->publish('message');
$topic->publish(['another message', 'third message']);

Read more about all the possibilities in the documentation page.

Client

In addition to the server (PHP) part, the client part is also present in most projects. In most cases, this is a browser in which the connection to the server is made using the WebSocket protocol.

const ws = new WebSocket('ws://127.0.0.1/broadcast');

ws.onopen = e => {
    const message = {
        command: 'join',
        topics:  ['channel-1', 'channel-2']
    };

    ws.send(JSON.stringify(message));
};

ws.onmessage = e => {
    const message = JSON.parse(e.data);

    console.log(`${message.topic}: ${message.payload}`);
}
try Spiral Framework

Examples

Examples are available in the corresponding directory ./example.

License

The MIT License (MIT). Please see LICENSE for more information. Maintained by Spiral Scout.

broadcast's People

Contributors

butschster avatar dependabot[bot] avatar rustamwin avatar rustatian avatar serafimarts avatar wolfy-j avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

rustamwin

broadcast's Issues

Can't get the default configuration to work

Hi, and thanks for the great ecosystem!

I am having a trouble getting the broadcast plugin to work. I've followed the example:

websockets:
    broker: default
    path: "/ws"

broadcast:
    default:
        driver: memory
        config: {}

Then I have

$rpc = \Spiral\Goridge\RPC\RPC::create('tcp://127.0.0.1:6001');
$broadcast = new Broadcast($rpc);
$broadcast->publish('channel-1', 'message for channel #1');

But in the logs I can see

backend-payments-1  | 2022-09-14T06:16:11.349Z	DEBUG	broadcast   	message was published	{"msg": "messages:{topics:\"channel-1\" payload:\"message for channel #1\"}"}
backend-payments-1  | 2022-09-14T06:16:11.349Z	WARN	broadcast   	no publishers was registered

From what I can see the error is triggered here

https://github.com/roadrunner-server/broadcast/blob/master/plugin.go#L99

Which can only happen if there are no registered publishers. They re registered by the method call of GetDriver, but for Gods love, I didn't find anywhere this method to be called, neither in endure or roadrunner, so not sure how to proceed to resolve the issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.