npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@amplication/plugin-broker-redis

v2.0.7

Published

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

Downloads

138,251

Readme

@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);
  }
}