IntegrationService Configuration
Configure custom services for integration flows
IntegrationService Configuration
Defines a custom service that can be used within integration flows. Services encapsulate reusable business logic and operations.
Schema Properties
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
| Title | string | No | - | Human-readable title for the service |
| Specification | string | Yes | - | Service implementation specification (Python code, script path, or package reference) |
| Parameters | Dictionary<string, string> | No | {} | Configuration parameters for the service |
YAML Examples
Python Script Service
apiVersion: weik.io/v1
kind: IntegrationService
metadata:
name: data-transformer
spec:
Title: Customer Data Transformer
Specification: |
def transform(data):
"""Transform customer data to target format"""
return {
'id': data.get('customer_id'),
'name': f"{data.get('first_name')} {data.get('last_name')}",
'email': data.get('email', '').lower(),
'created': data.get('registration_date')
}
Parameters:
OutputFormat: json
ValidateEmail: "true"
Package-Based Service
apiVersion: weik.io/v1
kind: IntegrationService
metadata:
name: pdf-generator
spec:
Title: Invoice PDF Generator
Specification: weikio.services.pdf:generate
Parameters:
TemplateEngine: jinja2
OutputPath: /data/invoices
Orientation: portrait
PageSize: A4
File-Based Service
apiVersion: weik.io/v1
kind: IntegrationService
metadata:
name: email-validator
spec:
Title: Email Validation Service
Specification: ./services/validators/email_validator.py
Parameters:
AllowDisposable: "false"
CheckMxRecords: "true"
MaxLength: "254"
Complex Service with Multiple Functions
apiVersion: weik.io/v1
kind: IntegrationService
metadata:
name: order-processor
spec:
Title: Order Processing Service
Specification: |
import logging
from datetime import datetime
logger = logging.getLogger(__name__)
def validate_order(order):
"""Validate order data"""
required_fields = ['customer_id', 'items', 'total']
return all(field in order for field in required_fields)
def calculate_discount(order):
"""Calculate applicable discounts"""
total = order.get('total', 0)
if total > 1000:
return total * 0.1
elif total > 500:
return total * 0.05
return 0
def process_order(order):
"""Process and enrich order data"""
if not validate_order(order):
raise ValueError("Invalid order data")
discount = calculate_discount(order)
final_total = order['total'] - discount
logger.info(f"Processing order {order.get('id')} with discount {discount}")
return {
**order,
'discount': discount,
'final_total': final_total,
'processed_at': datetime.utcnow().isoformat()
}
Parameters:
LogLevel: INFO
EnableValidation: "true"
Usage Notes
IntegrationService configurations define reusable services that can be invoked from integration flows. Services can contain business logic, data transformations, validations, or integrations with external systems.
Specification Formats
The Specification field supports three formats:
- Inline Python code - Write Python code directly in the YAML (useful for simple services)
- Package reference - Reference a function from an installed package using
package.module:functionsyntax - File path - Point to a local Python file containing the service implementation
Service Functions
Services typically expose functions that:
- Accept input parameters
- Perform operations or transformations
- Return results or raise exceptions
Functions can access the Parameters defined in the configuration through dependency injection or context.
Best Practices
- Keep services focused on a single responsibility
- Use descriptive names for service functions
- Include error handling and logging
- Document function parameters and return values
- Store complex services in separate files for maintainability
- Use parameters for configurable behavior
- Test services independently before integration