定制 phluxor/phluxor-remote 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

phluxor/phluxor-remote

最新稳定版本:0.2.0

Composer 安装命令:

composer require phluxor/phluxor-remote

包简介

remoting library for phluxor / actor model

README 文档

README

About

Phluxor Remoteは、Phluxorアクターシステムを活用したリモートアクターシステムを作成するためのライブラリです。

Phluxor Remote is a library that allows you to create remote actor systems in Phluxor.

It is inspired by the Proto.Remote.

with Phluxor Remote you can create a remote actor system that can communicate with other actor systems over network.

Phluxor Remote uses Swoole.

Between the two nodes, use the ProtoBuf serialization format.
Websocket is used as the transport layer.

Usage

Install

$ composer require phluxor/phluxor-remote

Node1

<?php

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

use Phluxor\ActorSystem;
use Phluxor\Remote\Config;
use Phluxor\Remote\Kind;
use Phluxor\Remote\Remote;
use Test\ProtoBuf\HelloRequest;
use Test\ProtoBuf\HelloResponse;

\Swoole\Coroutine\run(function () {
    \Swoole\Coroutine\go(function () {
        $system = ActorSystem::create();
        $config = new Config('localhost', 50053, Config::withUseWebSocket(true));
        $remote = new Remote($system, $config);
        $remote->start();
        $props = ActorSystem\Props::fromFunction(
            new ActorSystem\Message\ReceiveFunction(
                function (ActorSystem\Context\ContextInterface $context) {
                    $message = $context->message();
                    if ($message instanceof HelloRequest) {
                        $context->respond(new HelloResponse([
                            'Message' => 'Hello from remote node',
                        ]));
                    }
                }
            )
        );
        $system->root()->spawnNamed($props, 'hello');
    });
});

Node2

<?php

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

use Phluxor\ActorSystem;
use Phluxor\Remote\Config;
use Phluxor\Remote\Kind;
use Phluxor\Remote\Remote;
use Test\ProtoBuf\HelloRequest;
use Test\ProtoBuf\HelloResponse;

\Swoole\Coroutine\run(function () {
    \Swoole\Coroutine\go(function () {
        $system = ActorSystem::create();
        $config = new Config('localhost', 50052, Config::withUseWebSocket(true));
        $remote = new Remote($system, $config);
        $remote->start();
        $future = $system->root()->requestFuture(
            new ActorSystem\Ref(new ActorSystem\ProtoBuf\Pid([
                'address' => 'localhost:50053',
                'id' => 'hello',
            ])),
            new HelloRequest(),
            1
        );
        $r = $future->result()->value();
        $r->getMessage(); // Hello from remote node! 
    });
});

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2024-09-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固