I lost almost 2 days of googling and search trying to figure out what is wrong with my set up. All my services are running inside a Docker container, all properly connected (I have tested it)
I have a minimal Socket IO Server on Node.JS connected to Redis:
require('longjohn');
require('dotenv').load({silent: true});
process.env = process.env || {};
var PORT = process.env.SOCKET_PORT || 4567;
var io = require('socket.io').listen(PORT);
var redis = require('socket.io-redis');
io.adapter(redis({
host: process.env.REDIS_HOST || 'redis',
port: process.env.REDIS_PORT || 6379
}));
io.on('connection', function (socket) {
console.log(`New connection!`);
}
When I MONITOR this code on Redis, I got:
1520713149.833184 [0 172.20.0.8:40858] "info"
1520713149.833631 [0 172.20.0.8:40860] "info"
1520713149.834154 [0 172.20.0.8:40862] "info"
1520713149.839510 [0 172.20.0.8:40860] "subscribe" "socket.io#/#"
1520713149.840678 [0 172.20.0.8:40862] "subscribe" "socket.io-sync#request#/#"
Then a php App that connects and Emit to Redis
<?php
require(__DIR__.'/vendor/autoload.php');
$client = new Predis\Client([
'scheme' => 'tcp',
'host' => 'redis',
'port' => 6379,
]);
$client->connect();
$emitter = new SocketIO\Emitter($client);
$emitter->emit('event', 'payload str');
And on Redis:
"PUBLISH" "socket.io#emitter" "\x92\x83\xa4type\x02\xa4data\x92\xa5event\xabpayload str\xa3nsp\xa1/\x82\xa5rooms\x90\xa5flags\x90"
So it looks like all come to REDIS but the socket io server doesn't get the event for an Unknown reason.
I was thinking about the different channel socket.io#emitter
, socket.io#/#
and socket.io-sync#request#/#
used by both. But with all the article I have read, none of them used or changed them.
So maybe it's a package version that doesn't match? But all this version below are used by my co-workers... (I asked them for this problem, still looking)
On PHP, I use composer with:
{
"require": {
"rase/socket.io-emitter": "^0.7.0",
"predis/predis": "^1.0"
}
}
And on Socket IO Server, npm with:
{
"dependencies": {
"dotenv": "~1.2.0",
"longjohn": "~0.2.9",
"socket.io": "~1.3.7",
"socket.io-redis": "^1.1",
}
}
If someone has an idea, I'll appreciate a lot ;)
Edit:
My co-workers use Vagrant and I gave it a try to see if something was different and yes, there is a difference in the channel subscribed by the socket.io server.
It's psubscribe" "socket.io#*
instead of socket.io#/#
but they didn't touch anything about it and the sources are the same on both (docker and vagrant) kind of crazy right ?..