adonisjs/transmit

Add channel name scoping for different environments

Opened this issue ยท 5 comments

Package version

@adonisjs/transmit@1.0.0

Describe the bug

Is it possible to include some kind of channel name scoping when using Redis as transport provider. When using same Redis instance all environments receive event from Pub/sub.

Reproduction repo

No response

Hey @sivo1981?

Could you please elaborate on what you mean by "channel name scoping"?

Application with same code base is runing in two different environments "production" and "test". Using channel name lets say "users" and transmit transport Redis with connection to the same server instance it will result in sending events on both environments because redis pub/sub doesn't care about this, it just sends event to all clients subscribed to this channel.

This is also stated here: https://redis.io/docs/latest/develop/interact/pubsub/

Probably it would be the best options to prefix channel names based on some env variable so the final channel name would be ${CHANNEL_PREFIX}_users. This is already implemented for @adonisjs/redis package via REDIS_PREFIX for example.

You can define a keyPrefix in the configuration of the Transport, would that fix your issue?

import env from '#start/env'
import { defineConfig } from '@adonisjs/transmit'
import { redis } from '@adonisjs/transmit/transports'

export default defineConfig({
  transport: {
    driver: redis({
      host: env.get('REDIS_HOST'),
      port: env.get('REDIS_PORT'),
      password: env.get('REDIS_PASSWORD'),
      keyPrefix: 'transmit',
    })
  }
})

๐Ÿ“š https://docs.adonisjs.com/guides/digging-deeper/transmit#configuration

Yes, this would solve my issue if implementation would work also for channel names scoping. Currently it works only for storing keys.

Correct! I will update the code accordingly to use the keyPrefix set for our broadcasting channels.