denpamusic / laravel-zeromq

Fully unit-tested ZeroMQ driver for Laravel.
MIT License
17 stars 7 forks source link

Laravel-Lumen + ZeroMQ not receiving ANY events #4

Open typoworx-de opened 4 years ago

typoworx-de commented 4 years ago

I'm trying to use laravel-zeromq with bitcoind on laravel-lumen framework. Already installed composer-package and setup for config, ServiceProvider and Alias.

But after starting CLI-Command which should output some events, the script just silently loops through reactPHP loop-object and does nothing ...

My test code looks as follows:

        $loop = ZeroMQ()->connection('default')->subscribe(
            ['hashblock', 'hashtx'],
            function($blockhash, $sequence) {
                dd($blockhash);

                printf(
                    "New block %u found. Contains %u transactions.\n",
                    $block['height'],
                    $block->count('tx')
                );
            }
        );

        $loop->addPeriodicTimer(0.5, function () {
           echo "Still alive ...";
        });

        $loop->run();

The periodic-timer function is repeatingly executed. But there is no event received.

I already checked the culprid is nothing else. I've tested this nodejs-lib using example/sub.js and it works out of the box.

typoworx-de commented 4 years ago

Okay... I'm not at the final point getting it workiung, but it looks like I mistakenly named the config-file "zmq" instead of "zeromq" as lumen ("laravel light") does not have all artisan functions I had to do that manually (as also providing config-folder and config-loader on my own).

So the whole time before laravel-zeromq was trying to receive messages from host 'localhost', but in my case it's another IP provided by docker-container.

typoworx-de commented 4 years ago

Looks like it's working now. But I'm confused the onSuccess method callback inside subscrube method only accepts string as response?

In case of bitcoind there is an array-response which breaks this code. Why is there a type casting to string making the whole thing less flexible?

see here: https://github.com/denpamusic/laravel-zeromq/blob/master/src/Connection.php#L185

And this is the $message provided by bitcoind:

array:3 [
  0 => "hashtx"
  1 => b"ü†B\v\x1Cjí\x0E3³êR\"”ܸMål6v^ˆ5„ƒÆ,Û/\x05"
  2 => "jw\x1A\x00"
]
aliqasemzadeh commented 3 years ago

@typoworx-de @denpamusic I have this error too: Argument 1 passed to Denpa\ZeroMQ\Connection::onSuccess() must be of the type string, array given, called in C:\xampp\htdocs\btcserver\vendor\denpa\laravel-zeromq\src\Connection.php on line 167

at C:\xampp\htdocs\btcserver\vendor\denpa\laravel-zeromq\src\Connection.php:185 181| @param \React\ZMQ\SocketWrapper|null $socket 182| 183| @return void 184| /

185| protected function onSuccess(string $message, callable $callback, ?Socket $socket) : void 186| { 187| if ($callback($message) === false) { 188| if (! $socket->closed) { 189| $socket->close();

1 C:\xampp\htdocs\btcserver\vendor\denpa\laravel-zeromq\src\Connection.php:167 Denpa\ZeroMQ\Connection::onSuccess(Object(Closure), Object(React\ZMQ\SocketWrapper))

2 C:\xampp\htdocs\btcserver\vendor\evenement\evenement\src\Evenement\EventEmitterTrait.php:123 Denpa\ZeroMQ\Connection::Denpa\ZeroMQ{closure}()