Skip to main content

Worker

Overview​

Using ripple, you can create a process manager + Worker to start a custom service

Process Manager​

$manager = new \Ripple\Worker\Manager();

// API - The following operations are only allowed in the main process

//Send a reload signal to the specified service
Manager::reload(string|null $name);

//Add service
Manager::addWorker(Worker $worker);

// Remove service
Manager::removeWorker(string $name);

// Stop service
Manager::stop();

// Stop the specified service
Manager::stopWorker(string $name);

//Send a command to the specified service
Manager::commandToWorker(Command $command, string $name);

//Send commands to all services
Manager::commandToAll(Command $command);

Service process​

$ws = new Ws();

// API - The following operations are allowed in the service process for cross-service communication

//Send commands to all services
Worker::commandToAll(Command $command);

//Send a command to the specified service
Worker::commandToWorker(Command $command,string $name);

// Get a unique ID from the service group
Worker::syncId();

Service process interface​

class Ws extends \Ripple\Worker\Worker {

public function getName(): string
{
//TODO: return service name
}

public function getCount(): int
{
//TODO: Return the number of working processes
}

public function register(Manager $manager): void
{
//TODO: Initialization service, occurs in the main process, usually used for port monitoring/external controller monitoring, etc.
}

public function boot(): void
{
//TODO: Service startup, occurs in the worker process
}

public function onCommand(Command $workerCommand): void
{
//TODO: processing command, used for communication between services
}

public function onReload(): void
{
//TODO: Triggered when the working process receives the reload signal. After receiving this signal, the process should be actively released and the process closed.
}
}