A suite of simple apps to illustrate how to use most to handle redis events.
This suite may be run using docker or node.js 10.x. If you have docker installed already or would like to try it, follow the docker instructions. Otherwise, you will need to be running redis locally. Follow the node instructions to install node and redis.
- Install git
- Clone this repo:
git clone [email protected]:mostjs/core.git
cd examples/most-redis-docker
The remainder of this document assumes your working directory is
most-redis-docker
. You may have to modify some of the following directions
if you chose another folder name.
This project uses environment variables. If you are using the windows command
prompt, you may have to change some commands slightly to use env vars. For
example, rather than type REDIS_MYCHANNEL=my_channel npm run consume
, you
would type set REDIS_MYCHANNEL=my_channel&&npm run consume
.
- Install docker. (You will need to create a DockerHub account.)
- Build the docker image for this project:
docker build -t most-redis .
- Install node 10.x or the latest LTS version.
- Install the dependencies for this project:
npm install
- Install redis.
If you already have an instance of redis running, you may edit the docker-
compose.yml file in the most-redis-docker
folder. Change any values for
REDIS_HOST
and REDIS_PORT
according to your redis instance
When running this example, the publish service periodically sends JSON messages to redis, and the consume services receive the JSON messages and transform them. In your terminal(s), you should expect to see informational logs from each service as they start up and as they process the JSON messages.
- From the
most-redis-docker
folder, create and run the docker-compose network defined indocker-compose.yml
:
docker-compose up
Use Ctrl-C
to stop the docker-compose network.
You may also use docker-compose up -d
and docker-compose down
to start and
stop the docker-compose network in the background.
- From the
most-redis-docker
folder:
REDIS_MYCHANNEL=my_channel npm run consume
- Open a new terminal or shell, and from the
most-redis-docker
folder type:
REDIS_MYCHANNEL=my_channel npm run consume
- Open a third terminal or shell, and from the
most-redis-docker
folder type:
REDIS_MYCHANNEL=my_channel npm run publish
Both the consume
and publish
services accept env vars. If you are using
Docker, these may be modified in the docker-compose.yml
file. The following
env vars are used:
REDIS_PORT
: integer, default is6379
REDIS_HOST
: string, default is'127.0.0.1'
REDIS_CHANNEL
: string, requiredTIMEOUT
: integer, default is2500
- Easy: Change the channel name for one or more of the services.
- Easy: Change the timeout to 0 (there are two ways to do this). What happens?
- Master: Handle some messages differently from others. Hint: try most.js's
filter
,skipWhile
, ortakeWhile
in theconsume
service. - Master: Modify and configure the
publish
service to publish to 2 channels, then configure theconsume
services to each listen to one of those channels. Hint: accept a comma-separated list of channels viaREDIS_CHANNEL
? - Guru: Send invalid JSON from the
publish
service and userecoverWith
in theconsume
service to handle it. - Guru: Create a selective forwarding service by re-publishing some of the
messages from the
consume
service.