-
-
Notifications
You must be signed in to change notification settings - Fork 11
Description
I would like to propose a feature that facilitates a smoother integration of the RoadRunner server within a distributed environment. This would cater to scenarios where multiple instances of RoadRunner servers are being run on remote servers dedicated to different functions like cache management, job queues, and metric gathering, among others.
Background
The RoadRunner server provides an RPC interface enabling communication between the server and PHP applications. This communication includes commands such as updating cache storage or sending metrics to a plugin. Here you can find more information about RPC https://roadrunner.dev/docs/php-rpc
However, when RoadRunner servers are distributed (running multiple server instances on remote servers), there arises a necessity to manage these servers' RPC connections effectively. This is to ensure that each command reaches the correct server instance based on its dedicated function.
Proposal
Introducing a class like RoaRunnerConnectionManagerInterface which would allow a convenient way to manage these connections. The interface would receive a connection name and return the proper connection with the desired RoadRunner server.
Here’s a simplified outline of what the RoaRunnerConnectionManagerInterface interface could look like:
namespace Spiral\RoadRunnerBridge;
use Spiral\Goridge\RPC\RPCInterface;
interface RoaRunnerConnectionManagerInterface
{
public function connect(string $connection): RPCInterface;
}Configuration
Connections can be configured in a config file, and each connection is represented by a name along with its server address.
return [
'default' => env('RR_CONNECTION', 'app'),
'connections' => [
'app' => [
'address' => 'tcp://127.0.0.1:6001',
],
'cache-server' => [
'address' => 'tcp://127.0.0.1:6004',
],
'queue-server' => [
'address' => 'tcp://127.0.0.1:6002',
],
'metrics-server' => [
'address' => 'tcp://127.0.0.1:6003',
],
],
];Usage Example
In the context of managing a queue, connections can be set within specific bridge integrations:
use Spiral\RoadRunner\Jobs\Queue\MemoryCreateInfo;
use Spiral\RoadRunner\Jobs\Queue\AMQPCreateInfo;
return [
// ...
'connections' => [
// ...
'rr-amqp' => [
'driver' => 'roadrunner',
'connection' => 'queue-server',
'pipeline' => 'low-priority',
],
'rr-memory' => [
'driver' => 'roadrunner',
'pipeline' => 'in-memory',
],
],
];In scenarios where no connection is specified, the default connection would be utilized.
I am looking forward to feedback and further discussions regarding the feasibility and the potential integration of this feature.
