Connectors
Connectors enable Hub to interact with external systems, APIs, and services. Hub provides both built-in connectors (like HTTP) and a powerful framework for developing custom connectors.Table of Contents
Getting Started
Custom Connector Development
Plugin Development
Configuration & Registration
Advanced Topics
Connector Types
Hub supports three types of connectors:1. Built-in Connectors
- HTTP Connector: For REST APIs, web services, and HTTP-based integrations
- See HTTP Connector Documentation for details
2. Custom Connectors
- Embedded Connectors: Spring-managed beans within your Hub application
- Plugin Connectors: OSGI bundles for modular, hot-deployable connectors
3. Integration Patterns
- Wrapper Connectors: Custom connectors that use HTTP connector internally
- Protocol Connectors: For non-HTTP protocols (FTP, SFTP, message queues, etc.)
- Service Connectors: Integration with specific external services
Basic Usage
Connectors are used within exchanges in the DSL:HTTP Connector
Custom Connector
Connector with Complex Configuration
Quick Start
1. Simple Custom Connector
Create a basic custom connector:2. Register the Connector
3. Use in DSL
Creating Custom Connectors
Interface Implementation
Custom connectors implement theCustomConnector interface or extend CustomConnectorSupport:
Required Methods
type() - Connector Identifier
Returns the unique identifier used in DSL connector() calls:
- Simple names:
'sms','email','validation' - Versioned:
'mambu@mambu:1.2.3' - Namespaced:
'Screen-Sync@worldcheck.connectors'
exchange() - Core Logic
Implements the connector’s main functionality:
Optional Methods
config() - Input Validation
Defines the schema for connector configuration:
payload() - Result Schema
Defines the expected structure of connector results:
Payload Specifications
Payload specifications define data structure and validation rules for connector inputs and outputs.Basic Types
Advanced Validation
File Handling
Nested Structures
Date Validation
Error Handling
Exception Types
ConnectorErrorException - Retryable Errors
Used for temporary failures that should be retried:
UnretryableConnectorErrorException - Non-Retryable Errors
Used for permanent failures that should not be retried:
ConnectorException - System Errors
Used for unexpected system errors:
Error Response Structure
Structure error responses consistently:Testing Connectors
Unit Testing
Integration Testing with MockConnector
Mock Connector Patterns
OSGI Plugin Connectors
Plugin Connector Implementation
OSGI plugin connectors implement thecom.zenoo.hub.plugin.sdk.Connector interface:
Plugin Structure
build.gradle for Plugin
Plugin vs Embedded Connectors
| Aspect | Embedded Connectors | Plugin Connectors |
|---|---|---|
| Deployment | Built into application | Hot-deployable bundles |
| Interface | CustomConnector | plugin.sdk.Connector |
| Configuration | PayloadSpec validation | Manual input processing |
| Spring Integration | Full Spring support | Limited Spring features |
| Error Handling | Rich exception types | Basic error handling |
| Testing | Full MockConnector support | Limited testing tools |
Connector Registration
Programmatic Registration
HubConfigurer Bean
ConnectorActivator Patterns
Auto-Configuration
Hub provides auto-configuration for Spring Boot:Component Dependencies
Declare connector dependencies in components:Monitoring & Metrics
Connector Metrics
Hub automatically tracks metrics for all connectors:Built-in Metrics
- Request Count: Total number of connector invocations
- Duration: Request/response time metrics
- Error Rate: Success/failure ratios
- Retry Count: Number of retry attempts
Metric Tags
connector.name: Connector identifierconnector.type: “custom” or “http”component.name: Calling component namestatus: “success” or “error”
Custom Metrics
Add custom metrics in your connector:Logging Best Practices
Integration Patterns
HTTP Wrapper Pattern
Use HTTP connector within custom connectors:Service Integration Pattern
Async Processing Pattern
Best Practices
1. Configuration Design
- Use clear, descriptive field names
- Provide sensible defaults where possible
- Mark optional fields explicitly
- Validate input thoroughly
2. Error Handling
- Use appropriate exception types for different error scenarios
- Provide meaningful error messages and codes
- Include relevant context in error responses
- Log errors appropriately without exposing sensitive data
3. Performance
- Use reactive patterns for non-blocking operations
- Implement appropriate timeouts
- Use connection pooling for external resources
- Consider caching where appropriate
4. Security
- Never log sensitive configuration data
- Use secure credential storage mechanisms
- Validate all inputs to prevent injection attacks
- Follow principle of least privilege
5. Testing
- Write comprehensive unit tests
- Use mock connectors for integration testing
- Test error scenarios and edge cases
- Validate configuration schemas
6. Documentation
- Document connector purpose and capabilities
- Provide clear configuration examples
- Document error conditions and responses
- Include integration examples
Troubleshooting
Common Issues
Connector Not Found
- Verify connector is registered in
HubConfigurer - Check connector
type()method returns correct name - Ensure connector bean is properly configured
- Verify component dependencies include the connector
Configuration Validation Errors
- Check
PayloadSpecconfiguration matches usage - Verify all required fields are provided
- Review field names and types
- Test configuration validation in unit tests
Timeout Issues
- Increase exchange timeout:
timeout 60 - Optimize connector implementation
- Check external service availability
- Review retry strategies
Plugin Loading Failures
- Verify OSGI bundle manifest
- Check plugin dependencies
- Review class loading issues
- Validate plugin structure
Debugging Tips
-
Enable Debug Logging
-
Use Request IDs
-
Monitor Metrics
- Check connector success/error rates
- Review response times
- Monitor retry patterns
-
Test in Isolation
Performance Optimization
-
Connection Pooling
-
Caching
-
Async Processing
Related Documentation
- HTTP Connector - Built-in HTTP connector features
- DSL Reference - Exchange and connector DSL syntax
- Component Development - Creating components that use connectors
- Testing Guide - Testing strategies for connectors
- Monitoring - Monitoring and metrics for connectors
This documentation covers Hub connector development. For specific connector implementations, refer to their individual documentation or source code examples.