Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send command to business worker #28

Closed
sm2017 opened this issue Jul 2, 2017 · 2 comments
Closed

Send command to business worker #28

sm2017 opened this issue Jul 2, 2017 · 2 comments
Labels

Comments

@sm2017
Copy link

sm2017 commented Jul 2, 2017

Hi

According to the following codes
https://github.com/walkor/GatewayWorker/blob/master/src/Gateway.php#L409-L414

each client is indirectly connected to specific business worker

From another business worker I want to send a command to the specific business worker using clientId

In other words , If I have business worker A (BWA) and B (BWB) and clientId = X is connected to BWA , Some times I need from BWB send a command to BWA that do something

How is possible ?

@sm2017
Copy link
Author

sm2017 commented Jul 4, 2017

@walkor
any update ?

@walkor
Copy link
Owner

walkor commented Jul 7, 2017

There is a interprocess/multi-server communication component for workerman named channel.

Install workerman\channel with command
conposer require workerman/channel

Example.
Create Applications/YourProject/start_channel.php.

<?php
use Workerman\Worker;
require_once __DIR__ . '/vendor/autoload.php';

// Channel Server. 
$channel_server = new Channel\Server('0.0.0.0', 2206);

In Events.php.

Class Events
{
    public static function onWorkerStart($worker)
    {
        // Channel client connect to Channel Server.
        Channel\Client::connect('127.0.0.1', 2206);
        // Subscribe $worker->id event . 
        Channel\Client::on($worker->id, function($event_data){
             var_export($event_data);
        });
    }

    public static function onMessage($client_id, $data) {
        // Publish event to one business worker processes which id is 1.
        $worker_id = 1;
        $event_data = ['some', 'data...'];
        Channel\Client::publish($worker_id, $event_data);
    }
}

Refer walkor/workerman#175.

Sorry for the delay.

@walkor walkor added the question label Jul 7, 2017
@sm2017 sm2017 closed this as completed Aug 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants