moscajs / mosca

MQTT broker as a module
mosca.io
3.2k stars 513 forks source link

Server with persistence to Azure Redis Cache #670

Closed nachten closed 6 years ago

nachten commented 6 years ago

Hi There,

I got my development environment running with a local Redis server, but now I need to setup my production environment. The thing is that I use Azure Redis Cache with SSL + Authentication on.

My mosca servers settings look as follows:

var ascoltatore = {
    type: 'ioredis',
    redis: require('ioredis'),
    host: '<my_hostname>.redis.cache.windows.net',
    port: 6380,
    password: '<my_authentication_key>',
    return_buffers: true, 
};

var moscaSettings = {
    port: 8883,
    secure: {
        port: 8883,
        keyPath: '/ssl/server.key',
        certPath: '/ssl/server.crt'
    },
    allowNonSecure: false,
    backend: ascoltatore,
    persistence: {
        factory: mosca.persistence.Redis,
        port: 6380,
        host: '<my_hostname>.redis.cache.windows.net',
        password: '<my_authentication_key>',
    }
};

With these settings I can not get an connection to my Redis Cache in Azure.

But when I create a simple ioredis client solution like the example below, everything works like a charm ...

var redisClient = new Redis({
        port: 6380,
        host: '<my_hostname>.redis.cache.windows.net',
        password: '<my_authentication_key>',
        tls: {
               hostname: '<my_hostname>.redis.cache.windows.net'
        },
 });

Please help me understand what I should do to make my mqtt server work in my production environment.

nachten commented 6 years ago

I have found the problem ... in the documentation it states that the redis persistence class has the setting "redisOpts" http://www.mosca.io/docs/lib/persistence/redis.js.html#RedisPersistence But this redisOpts is nowhere used in the code https://github.com/mcollina/mosca/blob/master/lib/persistence/redis.js but "redisOptions" is ...

So when i change my code to this:


var ascoltatore = {
    type: 'ioredis',
    redis: require('ioredis'),
    host: '<my_hostname>.redis.cache.windows.net',
    port: 6380,
    password: '<my_authentication_key>',
    return_buffers: true, 
};

var moscaSettings = {
    port: 8883,
    secure: {
        port: 8883,
        keyPath: '/ssl/server.key',
        certPath: '/ssl/server.crt'
    },
    allowNonSecure: false,
    backend: ascoltatore,
    persistence: {
        factory: mosca.persistence.Redis,
        redisOptions: {
            port: 6380,
            host: '<my_hostname>.redis.cache.windows.net',
            password: '<my_authentication_key>',
            tls: {
                hostname: '<my_hostname>.redis.cache.windows.net'
            }
        }
    }
};

Problem is my server is now running accepting connections ... but for some reason I can not yet publish any messages on the server yet ...