Added configurable client for each replication driver.
This commit is contained in:
parent
00faff7f04
commit
5b6bdf49e4
|
|
@ -166,10 +166,41 @@ return [
|
|||
|
||||
'driver' => env('LARAVEL_WEBSOCKETS_REPLICATION_DRIVER', 'local'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Local Replication
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Local replication is actually a null replicator, meaning that it
|
||||
| is the default behaviour of storing the connections into an array.
|
||||
|
|
||||
*/
|
||||
|
||||
'local' => [
|
||||
|
||||
'client' => \BeyondCode\LaravelWebSockets\PubSub\Drivers\LocalClient::class,
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Redis Replication
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Redis replication relies on the Redis' Pub/Sub protocol. When users
|
||||
| are connected across multiple nodes, whenever some event gets triggered
|
||||
| on one instance, the rest of the instances get the same copy and, in
|
||||
| case the connected users to other instances are valid to receive
|
||||
| the event, they will receive it.
|
||||
|
|
||||
*/
|
||||
|
||||
'redis' => [
|
||||
|
||||
'connection' => env('LARAVEL_WEBSOCKETS_REPLICATION_CONNECTION', 'default'),
|
||||
|
||||
'client' => \BeyondCode\LaravelWebSockets\PubSub\Drivers\RedisClient::class,
|
||||
|
||||
],
|
||||
|
||||
],
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@ namespace BeyondCode\LaravelWebSockets\Console;
|
|||
|
||||
use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger;
|
||||
use BeyondCode\LaravelWebSockets\Facades\WebSocketsRouter;
|
||||
use BeyondCode\LaravelWebSockets\PubSub\Drivers\LocalClient;
|
||||
use BeyondCode\LaravelWebSockets\PubSub\Drivers\RedisClient;
|
||||
use BeyondCode\LaravelWebSockets\PubSub\ReplicationInterface;
|
||||
use BeyondCode\LaravelWebSockets\Server\Logger\ConnectionLogger;
|
||||
use BeyondCode\LaravelWebSockets\Server\Logger\HttpLogger;
|
||||
|
|
@ -189,17 +187,16 @@ class StartWebSocketServer extends Command
|
|||
*/
|
||||
public function configurePubSub()
|
||||
{
|
||||
if (config('websockets.replication.driver', 'local') === 'local') {
|
||||
$this->laravel->singleton(ReplicationInterface::class, function () {
|
||||
return new LocalClient;
|
||||
});
|
||||
}
|
||||
$this->laravel->singleton(ReplicationInterface::class, function () {
|
||||
$driver = config('websockets.replication.driver', 'local');
|
||||
|
||||
if (config('websockets.replication.driver', 'local') === 'redis') {
|
||||
$this->laravel->singleton(ReplicationInterface::class, function () {
|
||||
return (new RedisClient)->boot($this->loop);
|
||||
});
|
||||
}
|
||||
$client = config(
|
||||
"websockets.replication.{$driver}.client",
|
||||
\BeyondCode\LaravelWebSockets\PubSub\Drivers\LocalClient::class
|
||||
);
|
||||
|
||||
return (new $client)->boot($this->loop);
|
||||
});
|
||||
|
||||
$this->laravel
|
||||
->get(ReplicationInterface::class)
|
||||
|
|
|
|||
|
|
@ -258,19 +258,18 @@ abstract class TestCase extends BaseTestCase
|
|||
{
|
||||
// Replace the publish and subscribe clients with a Mocked
|
||||
// factory lazy instance on boot.
|
||||
if (config('websockets.replication.driver') === 'redis') {
|
||||
$this->app->singleton(ReplicationInterface::class, function () {
|
||||
return (new RedisClient)->boot(
|
||||
LoopFactory::create(), Mocks\RedisFactory::class
|
||||
);
|
||||
});
|
||||
}
|
||||
$this->app->singleton(ReplicationInterface::class, function () {
|
||||
$driver = config('websockets.replication.driver', 'local');
|
||||
|
||||
if (config('websockets.replication.driver') === 'local') {
|
||||
$this->app->singleton(ReplicationInterface::class, function () {
|
||||
return new LocalClient;
|
||||
});
|
||||
}
|
||||
$client = config(
|
||||
"websockets.replication.{$driver}.client",
|
||||
\BeyondCode\LaravelWebSockets\PubSub\Drivers\LocalClient::class
|
||||
);
|
||||
|
||||
return (new $client)->boot(
|
||||
LoopFactory::create(), Mocks\RedisFactory::class
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
protected function runOnlyOnRedisReplication()
|
||||
|
|
|
|||
Loading…
Reference in New Issue