Deployment Methods
Pulsar Functions can be deployed using:- pulsar-admin CLI: Command-line deployment and management
- REST API: Programmatic deployment via HTTP
- Function configuration files: YAML-based configuration
Deploying with pulsar-admin
Thepulsar-admin functions command provides complete function lifecycle management.
Basic Deployment
Package Your Function
Package your function code as a JAR (Java), Python file, or Go binary.
Java
Python
Language-Specific Deployment
Configuration File Deployment
Use YAML configuration files for complex deployments:Basic Configuration
example-function-config.yaml
Stateful Function Configuration
stateful-function-config.yaml
Window Function Configuration
window-function-config.yaml
Advanced Configuration
Multiple Input Topics
Process messages from multiple topics:Topic Pattern Subscriptions
Subscribe to topics matching a pattern:User Configuration
Pass custom configuration to your function:Resource Allocation
Configure CPU and memory resources:Parallelism and Scaling
Run multiple instances for higher throughput:Processing Guarantees
Configure delivery semantics:ATLEAST_ONCE(default): Messages processed at least onceATMOST_ONCE: Messages processed at most onceEFFECTIVELY_ONCE: Message effects applied exactly once
Log Configuration
Redirect logs to a Pulsar topic:Secrets Management
Provide secrets to functions:Function Management
Update Function
Update a running function:Get Function Info
Retrieve function configuration:Check Function Status
View runtime status of all instances:- Number of running instances
- Processed message count
- Failure count
- Average processing latency
View Function Stats
Get detailed processing statistics:Restart Function
Restart all or specific function instances:Stop Function
Stop function without deleting:Start Function
Start a stopped function:Delete Function
Remove function from cluster:Testing in Production
Trigger Function Manually
Test function with sample input:View Function Logs
Stream function logs:Monitoring and Metrics
Built-in Metrics
Pulsar Functions automatically export metrics:- pulsar_function_processed_successfully_total: Total successful messages
- pulsar_function_system_exceptions_total: System errors
- pulsar_function_user_exceptions_total: User code errors
- pulsar_function_process_latency_ms: Processing latency
- pulsar_function_last_invocation: Timestamp of last invocation
Custom Metrics
View custom metrics recorded viacontext.recordMetric():
Best Practices
Use Configuration Files
Store function configuration in version control for reproducible deployments and easy rollback.
Start with Low Parallelism
Begin with parallelism=1 and increase based on monitoring. Ensure your function is thread-safe before increasing parallelism.
Configure Appropriate Resources
Set CPU and memory based on function requirements. Monitor resource usage and adjust as needed.
Enable Appropriate Processing Guarantees
Use EFFECTIVELY_ONCE only when needed, as it has performance overhead. ATLEAST_ONCE is sufficient for idempotent operations.
Monitor Function Health
Set up alerts on function exceptions, processing latency, and custom metrics.
Troubleshooting
Function Won’t Start
Check function status and logs:- Invalid class name or missing dependencies
- Insufficient resources
- Topic subscription failures
High Exception Rate
View detailed stats:- User code exceptions in logs
- Input message format mismatches
- External service availability
Performance Issues
Monitor processing latency and throughput:- Increase parallelism for CPU-bound functions
- Use async operations for I/O-bound functions
- Check for bottlenecks in state storage
Next Steps
Runtime Configuration
Learn about function runtime modes and configuration
Developing Functions
Review function development best practices