subscriber closing abruptly in pubsub
raghuveer opened this issue · comments
I am trying to use Amphp/redis for Redis Pubsub and everytime I try running subscriber in one putty window and publish messages using another putty window, the first message is being pushed, second message not published and third message making the subscriber to exit
to ensure timeout donot happen, using require in_set based directive as well
I ran redis-cli with MONITOR command beside in another putty window, no errors observed too
please share your inputs
thank you
code in publish.php
require 'vendor/autoload.php';
use Amp\Redis\Config;
use Amp\Redis\Redis;
use Amp\Redis\RemoteExecutor;
use Amp\Iterator;
use Amp\Delayed;
use Amp\Loop;
use Amp\Redis\Subscriber;
use Amp\Redis\RedisException;
use Amp\Redis\Subscription;
use Amp\Socket\Socket;
Amp\Loop::run(static function () {
// $config = Config::fromUri('tcp://localhost:6379?pass=foobar');
$redis = new Redis(new RemoteExecutor(Config::fromUri('tcp://localhost:6379')));
$subscriber = new Subscriber(Config::fromUri('redis://'));
$result = yield $redis->publish("myChannel","SriRama");
var_dump($result);
});
code in subscriber.php
require 'vendor/autoload.php';
use Amp\Redis\Config;
use Amp\Redis\Redis;
use Amp\Redis\RemoteExecutor;
use Amp\Iterator;
use Amp\Delayed;
use Amp\Loop;
use Amp\Redis\Subscriber;
use Amp\Redis\RedisException;
use Amp\Redis\Subscription;
use Amp\Socket\Socket;
ini_set('default_socket_timeout', -1);
Amp\Loop::run(static function () {
// $config = Config::fromUri('tcp://localhost:6379?pass=foobar');
$redis = new Redis(new RemoteExecutor(Config::fromUri('tcp://localhost:6379')));
$subscriber = new Subscriber(Config::fromUri('redis://'));
$subscription = yield $subscriber->subscribe("myChannel");
yield $subscription->advance();
$result = $subscription->getCurrent();
var_dump($result);
});
The default timeout won't have any effect.
The problem is you only advance the subscription once instead of putting this into a while (yield $subscription->advance()) loop.
while we tried using while loop, as we remember using similarly with select query in amphp/mysql and earlier with Rabbitmq message queue, somehow we did not see progress when using while loop in some of our attempts and then we did revert to previous example and wrote this issue
Thanks a lot, for making the right pointer @kelunik and it is working now, I had tested subscribing in multiple putty windows, while publishing from same putting window and monitoring the same in another