Adonis, Adonisjs, Redis RPC, for Adonisjs V5, Please follow
The @craftnotion/adonisjs-advance-redis-rpc
package is a powerful RPC (Remote Procedure Call) provider designed specifically for AdonisJS applications. It leverages Redis pub/sub transport for efficient communication between server and client instances. This package simplifies the implementation of distributed systems by enabling seamless communication between different parts of your application.
Before installing the package, ensure you have Redis installed and configured. You can follow the instructions provided in the AdonisJS documentation for setting up Redis. Once Redis is set up, you can install the package via npm:
npm i @craftnotion/adonisjs-advance-redis-rpc
node ace configure @craftnotion/adonisjs-advance-redis-rpc
The server, methods, and client can be initiated in #start/redis_rpc.ts file to ensure seamless communication within your AdonisJS application.
In server mode, you can create a server with a specific name and add handlers for methods that can be invoked remotely.
import redisRPC from '@craftnotion/adonisjs-advance-redis-rpc/services/main'
async run(){
await redisRPC.server('example') // Create a server with name example
redisRPC.addHandler('exampleMethod', async ({ data }) => {
console.log(data);
})
}
run();
import redisRPC from '@craftnotion/adonisjs-advance-redis-rpc/services/main'
async run(){
await redisRPC.client() // Create a client
}
run();
import Route from '@ioc:Adonis/Core/Route'
import redisRPC from '@craftnotion/adonisjs-advance-redis-rpc/services/main'
Route.get('example', async () => {
const result = await redisRPC.call('example.exampleMethod', { data: 'message' })
return result
})
Crafted with ❤️ by Craftnotion