Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@amplication/plugin-broker-redis

Package Overview
Dependencies
Maintainers
8
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@amplication/plugin-broker-redis

Use a Redis message broker in the service generated by Amplication.

  • 2.0.7
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
11K
decreased by-59.53%
Maintainers
8
Weekly downloads
 
Created
Source

@amplication/plugin-broker-redis

NPM Downloads

Use a Redis message broker in the service generated by Amplication.

Purpose

This plugin adds the required code to use Redis as a message broker in the service generated by Amplication.

It updates the following parts:

  • Adds the required dependencies to package.json.
  • Adds the required environment variables to .env.
  • Adds a module RedisModule with a service RedisProducerService that can be used to emit messages and a controller to respond to topic events.
  • Adds the RedisModule configured to use Redis to the app.module.ts module imports list.
  • Adds the required redis service to the docker-compose.yml as docker-compose.dev.yml files.

Configuration

The port setting is the port that will be used for the url of the redis server.

The host setting is the host that will be used for the url of the redis server.

The retryAttempts setting is the number of times to retry a message.

The retryDelay setting is the delay between each message retry attempt.

The enableTls setting is set to true when TLS should be used.

If no configuration is provided the .amplicationrc.json file will use be used as the default values.

{
  "host": "localhost",
  "port": 6379,
  "retryAttempts": 3,
  "retryDelay": 3,
  "enableTls": false
}

For more information about TLS configuration, check the ioredis docs https://github.com/redis/ioredis#tls-options

Scripts

build

Running npm run build will bundle your plugin with Webpack for production.

dev

Running npm run dev will watch your plugin's source code and automatically bundle it with every change.

test

Running npm run test will run the plugin's test suite.

Usage

This plugin provides you with a Redis broker module that you can use in your service. To configure, set the following environment variables:

REDIS_BROKER_HOST - the host that will be used in the url of the Redis server.

REDIS_BROKER_PORT - the port that will be used in the url of the Redis server.

REDIS_BROKER_RETRY_ATTEMPTS - The number of times to retry a message.

REDIS_BROKER_RETRY_DELAY - The delay between each message retry attempt.

REDIS_BROKER_ENABLE_TLS - Set to "true" when TLS should be used.

An example of how to use the Redis module:

In a controller:

export class ModelController extends ModelControllerBase {
    constructor(protected readonly service: ModelService,
    private redisService: RedisProducerService) {
        super(service);
    }

    @Get()
    async respondToUser(): Promise<void> {
        await this.redisService.emit(MessageBrokerTopics.FirstTopic, { message: "hello, world!" });
        return "Done";
    }
}

Customization of the Redis controller to perform desired tasks:

@Controller("redis-controller")
export class RedisController {
  @EventPattern("firstTopic")
  async onFirstTopic(
    @Payload()
    message: RedisMessage
  ): Promise<void> {
    console.log("Received message:", message);
  }
}

FAQs

Package last updated on 14 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc