# Core services communications In `RustiqIOT`, services can communicate with each other using XML RPC. The first service that is available for the services is the admin embedded. Each service has its own manifest.json descriptor which contains its configuration including the XML-RPC port. Here is below the process of adminembedded to discover and connect to the other services. ```{mermaid} graph TD A[Admin Embedded Service] -->|1_Reads| B[Service 1 manifest.json] A -->|1_Reads| H[Service 2 manifest.json] A -->|1_Reads| I[Service N manifest.json] B -->|2_Contains| C1[Service 1 Configuration] H -->|2_Contains| C2[Service 2 Configuration] I -->|2_Contains| C3[Service N Configuration] C1 -->|3_Extracts| D1[XML-RPC Port] C2 -->|3_Extracts| D2[XML-RPC Port] C3 -->|3_Extracts| D3[XML-RPC Port] A -->|4_Connects to using XML-RPC, and the port| E[Service 1] A -->|4_Connects to using XML-RPC, and the port| F[Service 2] A -->|4_Connects to using XML-RPC, and the port| G[Service N] subgraph "Service 1" B C1 D1 E end subgraph "Service 2" H C2 D2 F end subgraph "Service N" I C3 D3 G end style A fill:#f9f,stroke:#333 style B fill:#ff9,stroke:#333 style H fill:#ff9,stroke:#333 style I fill:#ff9,stroke:#333 style C1 fill:#ff9,stroke:#333 style C2 fill:#ff9,stroke:#333 style C3 fill:#ff9,stroke:#333 style D1 fill:#ff9,stroke:#333 style D2 fill:#ff9,stroke:#333 style D3 fill:#ff9,stroke:#333 style E fill:#9f9,stroke:#333 style F fill:#9f9,stroke:#333 style G fill:#9f9,stroke:#333 ``` ## Example of service's manifest.json Here's an example of a service manifest.json file: ```json { "application_id": "", "application_name": "dev_mock_transfert", "application_version": "1.0", "application_description": "transfer_logic", "application_commandline": "/bin/python3 transfert.py", "monitoring_status_file_path": "status.json", "running_user": "user", "additional_properties": {}, "content_path": "content_path", "service_name": "transfer", "service_port": 8013 } ``` Key manifest fields: - `application_name`: Unique identifier for the service container (the application name) (no special characters except underscores) - `service_port`: The XML-RPC communication port used by Admin Embedded to connect to the service - `service_name`: Name of the service(s) hosted by this application (can be comma-separated for multiple services) - `application_commandline`: The command used to start the service executable - `monitoring_status_file_path`: Path where the service reports its status ## Service calling example The Admin Embedded service provides a `call_service` method that allows services to communicate with each other. Here's how to use it: ### Syntax ```python call_service(service_name: str, method_name: str, *args) ``` Parameters: - `service_name`: The name of the target service as defined in its manifest.json - `method_name`: The name of the method to call on the target service - `*args`: Variable number of arguments to pass to the called method ### Examples 1. Basic service call without parameters: ```python # Call the 'get_status' method on the 'transfer' service result = admin_embedded.call_service("transfer", "get_status") ``` 2. Service call with parameters: ```python # Call the 'process_data' method on the 'transfer' service with parameters data = {"id": 123, "value": "test"} result = admin_embedded.call_service("transfer", "process_data", data) ``` ### Error Handling The `call_service` method will raise exceptions if: - The target service is not available - The specified method doesn't exist - The method call fails on the target service It's recommended to wrap service calls in try-except blocks: ```python try: result = admin_embedded.call_service("transfer", "get_status") except Exception as e: print(f"Service call failed: {e}") ``` Note: All service methods called through `call_service` must be explicitly exposed via XML-RPC on the target service.