delay
Introduce delays in flow execution for rate limiting, timing coordination, and scheduled operations.
delay Block
The delay block delays each message passing through the node or limits the rate at which they can pass.
Overview
When configured to delay messages, the delay interval can be a fixed value, a random value within a range or dynamically set for each message. Each message is delayed independently of any other message, based on the time of its arrival.
When configured to rate limit messages, their delivery is spread across the configured time period. The status shows the number of messages currently in the queue. It can optionally discard intermediate messages as they arrive.
If set to allow override of the rate, the new rate will be applied immediately, and will remain in effect until changed again, the node is reset, or the flow is restarted.
The rate limiting can be applied to all messages, or group them according to their msg.topic value. When grouping, intermediate messages are automatically dropped. At each time interval, the node can either release the most recent message for all topics, or release the most recent message for the next topic.
Note: In rate limit mode the maximum queue depth can be set by a property in your settings.js file. For example nodeMessageBufferMaxLength: 1000,
Configuration Options
Delay Type
Choose the type of delay to apply:
Fixed Delay
- Delay: Fixed time delay (e.g., 5 seconds, 1 minute)
- Units: Seconds, minutes, hours, or milliseconds
Random Delay
- Min Delay: Minimum delay time
- Max Delay: Maximum delay time
- Units: Seconds, minutes, hours, or milliseconds
Rate Limiting
- Rate: Number of messages per time period
- Time Period: Seconds, minutes, or hours
- Burst Size: Maximum number of messages to allow in burst
Queue Management
Queue Size
- Max Queue Size: Maximum number of messages to queue
- Drop Policy: What to do when queue is full:
- Drop New: Drop new messages when queue is full
- Drop Old: Drop oldest messages when queue is full
Message Handling
- Pass Through: Allow messages to pass through without delay
- Queue Messages: Queue messages for delayed processing
Common Use Cases
Rate Limiting API Calls
Limit the rate of API requests to avoid hitting rate limits:
{
"delayType": "rate",
"rate": 10,
"timePeriod": "minute",
"maxQueueSize": 100,
"dropPolicy": "dropNew"
}Batch Processing Delays
Add delays between batch processing operations:
{
"delayType": "fixed",
"delay": 2,
"units": "seconds"
}Random Processing Times
Simulate realistic processing times with random delays:
{
"delayType": "random",
"minDelay": 1,
"maxDelay": 5,
"units": "seconds"
}Scheduled Operations
Implement scheduled processing with delays:
{
"delayType": "fixed",
"delay": 30,
"units": "minutes"
}Throttling High-Volume Data
Throttle high-volume data streams:
{
"delayType": "rate",
"rate": 100,
"timePeriod": "minute",
"maxQueueSize": 1000,
"dropPolicy": "dropOld"
}Advanced Features
Dynamic Delays
Use expressions to calculate delays dynamically:
{
"delayType": "fixed",
"delay": "{{msg.payload.priority === 'high' ? 1 : 5}}",
"units": "seconds"
}Conditional Delays
Apply delays based on message content:
{
"delayType": "fixed",
"delay": "{{msg.payload.retryCount * 2}}",
"units": "seconds"
}Queue Monitoring
Monitor queue status and performance:
{
"delayType": "rate",
"rate": 50,
"timePeriod": "minute",
"maxQueueSize": 500,
"dropPolicy": "dropNew",
"monitorQueue": true
}Tips
- Use rate limiting to respect external API rate limits
- Implement random delays to avoid thundering herd problems
- Set appropriate queue sizes based on your system capacity
- Use drop policies to handle overflow gracefully
- Monitor queue performance to optimize delay settings
- Consider using delays for testing and simulation
- Use fixed delays for predictable timing requirements
Notes
- Delays are applied per message, not per flow
- Queue size limits help prevent memory issues
- Rate limiting is approximate and may vary slightly
- Random delays help distribute load more evenly
- The block preserves message order when possible
- Delays are measured from when the message arrives at the block