* Add support for exclusive consumer mode for Redis Message Queue * Bump version * add unit tests --------- Co-authored-by: Massimiliano Pippi <mpippi@gmail.com>
Using Redis as Message Queue provider
Note
This example is mostly based on the Quick Start, see there for more details.
We'll be deploying a simple workflow on a container running LlamaDeploy using Redis as the message queue provider. The Redis container will be started in a different container using Docker Compose.
This is the code defining our deployment, with comments to the relevant bits:
name: RedisMessageQueue
control-plane:
port: 8000
message-queue:
type: redis
# what follows depends on what's in the docker compose file
host: redis
port: 6379
default-service: counter_workflow_service
services:
counter_workflow_service:
name: Counter Workflow
source:
type: local
name: .
path: workflow:counter_workflow
Note how we the deployment file contains the message-queue key to instruct LlamaDeploy to use
Redis as the message queue provider.
Before starting the containers, two things to note about how LlamaDeploy is configured:
- We mount our application, consisting of the
deployment.ymlfile and a Python moduleworkflow.pycontaining the LlamaIndex code implementing the workflow, under the path/opt/appinside the container - We set the
LLAMA_DEPLOY_APISERVER_RC_PATHenvironment variable so that when LlamaDeploy starts, it will look under the/opt/appfolder for deployments to create automatically.
We can now start the Docker containers using Compose:
$ docker compose up -d
When the containers are up and running, we can use llamactl from our local host to
interact with the deployment:
$ llamactl status
LlamaDeploy is up and running.
Active deployments:
- RedisMessageQueue
Our workflow is now part of the RedisMessageQueue deployment and ready to serve requests! Since we want to persist
a counter across workflow runs, first we manually create a session:
$ llamactl sessions create -d RedisMessageQueue
session_id='<YOUR_SESSION_ID>' task_ids=[] state={}
Then we run the workflow multiple times, always using the same session we created in the previous step:
$ lamactl run --deployment RedisMessageQueue --arg amount 3 -i <YOUR_SESSION_ID>
Current balance: 3.0
$ lamactl run --deployment RedisMessageQueue --arg amount 3 -i <YOUR_SESSION_ID>
Current balance: 3.5
Note: If you have multiple replicas of the workflow and control plane and only want one replica to process messages,
set REDIS_EXCLUSIVE_MODE to true.