spiral/roadrunner-broadcast 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

spiral/roadrunner-broadcast

最新稳定版本:v2.1.0

Composer 安装命令:

composer require spiral/roadrunner-broadcast

包简介

RoadRunner broadcast plugin bridge

README 文档

README

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.

统计信息

  • 总下载量: 37.16k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 12
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 12
  • Watchers: 11
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-06-29