CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-alibaba-csp--sentinel-cluster-client-default

Default cluster client implementation for Sentinel cluster flow control

Pending
Overview
Eval results
Files

command-interface.mddocs/

Command Interface

The command interface provides HTTP endpoints for runtime configuration and monitoring of cluster client settings. These handlers enable dynamic reconfiguration and status queries without restarting the application.

Capabilities

Modify Cluster Client Configuration

HTTP command handler for dynamically updating cluster client configuration including server assignments and timeout settings.

/**
 * Command handler for modifying cluster client configuration
 * Endpoint: cluster/client/modifyConfig
 */
@CommandMapping(name = "cluster/client/modifyConfig", desc = "modify cluster client config")
public class ModifyClusterClientConfigHandler implements CommandHandler<String> {
    /**
     * Handle configuration modification request
     * @param request command request with URL-encoded JSON data parameter
     * @return success message or error response
     */
    public CommandResponse<String> handle(CommandRequest request);
}

Usage Examples:

// The handler expects a "data" parameter with URL-encoded JSON
// POST /cluster/client/modifyConfig?data=<encoded-json>

// Example JSON payload (before URL encoding):
{
    "serverHost": "new-cluster-server.example.com",
    "serverPort": 8719,
    "requestTimeout": 5000,
    "clientState": 2
}

// The handler will:
// 1. URL decode the data parameter
// 2. Parse JSON into ClusterClientStateEntity
// 3. Apply configuration via ClusterClientConfigManager
// 4. Return success or error response

Fetch Cluster Client Configuration

HTTP command handler for retrieving current cluster client configuration and state information.

/**
 * Command handler for fetching cluster client configuration
 * Endpoint: cluster/client/fetchConfig
 */
@CommandMapping(name = "cluster/client/fetchConfig", desc = "get cluster client config")
public class FetchClusterClientConfigHandler implements CommandHandler<String> {
    /**
     * Handle configuration fetch request
     * @param request command request (no parameters required)
     * @return JSON string containing current client state and configuration
     */
    public CommandResponse<String> handle(CommandRequest request);
}

Usage Examples:

// GET /cluster/client/fetchConfig
// Returns JSON response with current configuration:

{
    "serverHost": "cluster-server.example.com",
    "serverPort": 8719,
    "requestTimeout": 3000,
    "clientState": 2
}

// Client states:
// 0 = CLIENT_STATUS_OFF
// 1 = CLIENT_STATUS_PENDING  
// 2 = CLIENT_STATUS_STARTED

Configuration State Entity

Data transfer object for command interface operations that bridges HTTP requests and internal configuration classes.

/**
 * Entity for transferring cluster client state via command interface
 */
public class ClusterClientStateEntity {
    /**
     * Get server hostname or IP address
     * @return server host string
     */
    public String getServerHost();
    
    /**
     * Set server hostname or IP address
     * @param serverHost hostname or IP
     * @return this entity for fluent chaining
     */
    public ClusterClientStateEntity setServerHost(String serverHost);
    
    /**
     * Get server port number
     * @return server port
     */
    public Integer getServerPort();
    
    /**
     * Set server port number
     * @param serverPort port number (1-65535)
     * @return this entity for fluent chaining
     */
    public ClusterClientStateEntity setServerPort(Integer serverPort);
    
    /**
     * Get current client state
     * @return client state constant
     */
    public Integer getClientState();
    
    /**
     * Set client state
     * @param clientState state constant (OFF/PENDING/STARTED)
     * @return this entity for fluent chaining
     */
    public ClusterClientStateEntity setClientState(Integer clientState);
    
    /**
     * Get request timeout setting
     * @return timeout in milliseconds
     */
    public Integer getRequestTimeout();
    
    /**
     * Set request timeout
     * @param requestTimeout timeout in milliseconds
     * @return this entity for fluent chaining
     */
    public ClusterClientStateEntity setRequestTimeout(Integer requestTimeout);
    
    /**
     * Convert to internal client configuration object
     * @return ClusterClientConfig with timeout settings
     */
    public ClusterClientConfig toClientConfig();
    
    /**
     * Convert to internal server assignment configuration
     * @return ClusterClientAssignConfig with server details
     */
    public ClusterClientAssignConfig toAssignConfig();
}

Usage Examples:

import com.alibaba.csp.sentinel.command.entity.ClusterClientStateEntity;

// Create configuration entity
ClusterClientStateEntity entity = new ClusterClientStateEntity()
    .setServerHost("new-server.example.com")  
    .setServerPort(8719)
    .setRequestTimeout(5000)
    .setClientState(ClientConstants.CLIENT_STATUS_STARTED);

// Convert to internal configuration objects
ClusterClientConfig clientConfig = entity.toClientConfig();
ClusterClientAssignConfig assignConfig = entity.toAssignConfig();

// Apply configurations
ClusterClientConfigManager.applyNewConfig(clientConfig);
ClusterClientConfigManager.applyNewAssignConfig(assignConfig);

Command Integration

The command handlers integrate with Sentinel's HTTP command system and are automatically registered via the @CommandMapping annotation.

Command Registration:

// Handlers are automatically discovered and registered by Sentinel
// Access via HTTP endpoints:

// Modify configuration:
// POST http://host:port/cluster/client/modifyConfig?data=<url-encoded-json>

// Fetch configuration:  
// GET http://host:port/cluster/client/fetchConfig

Error Handling:

// Command responses include success/failure status
CommandResponse<String> response = handler.handle(request);

if (response.isSuccess()) {
    String result = response.getResult();
    System.out.println("Command succeeded: " + result);
} else {
    Exception exception = response.getException();
    System.err.println("Command failed: " + exception.getMessage());
}

JSON Serialization

The command interface uses FastJSON for JSON serialization and deserialization of configuration data.

Required Dependencies:

import com.alibaba.fastjson.JSON;

// Serialization
String json = JSON.toJSONString(stateEntity);

// Deserialization  
ClusterClientStateEntity entity = JSON.parseObject(json, ClusterClientStateEntity.class);

Thread Safety

All command handlers are stateless and thread-safe. Multiple concurrent command requests can be processed safely. The underlying configuration manager handles synchronization of configuration updates.

Security Considerations

Command handlers should be protected with appropriate authentication and authorization mechanisms when deployed in production environments. The modify configuration endpoint can change critical cluster settings and should be restricted to authorized administrators.

Install with Tessl CLI

npx tessl i tessl/maven-com-alibaba-csp--sentinel-cluster-client-default

docs

cluster-token-client.md

codec-system.md

command-interface.md

configuration.md

index.md

network-transport.md

tile.json