Skip to content

Simple RPC Provider for Adonis 5, based on Redis pub/sub transport

License

Notifications You must be signed in to change notification settings

Craftnotion/adonis-advance-redis-rpc

 
 

Repository files navigation

@craftnotion/adonisjs-advance-redis-rpc

Adonis, Adonisjs, Redis RPC, for Adonisjs V5, Please follow

npm-image license-image typescript-image

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.

Installation

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

Usage

The server, methods, and client can be initiated in #start/redis_rpc.ts file to ensure seamless communication within your AdonisJS application.

Server Mode

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();

Client Mode

import redisRPC from '@craftnotion/adonisjs-advance-redis-rpc/services/main'

async run(){

  await redisRPC.client() // Create a client
}

run();

Calling Methods

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

About

Simple RPC Provider for Adonis 5, based on Redis pub/sub transport

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 96.4%
  • JavaScript 3.6%