Chenile Service Registry And Proxies Guide
Copied from `chenile-ppt/docs/chenile-service-registry-and-proxies-guide.md` (framework docs) on 1 December 2026.
This guide documents how chenile-service-registry and chenile-proxies work together, and how to replace direct RestClient usage with a Chenile proxy.
Why these two repositories matter together
chenile-service-registry answers:
- what remote Chenile services exist
- what operations they expose
- what URLs and return types they advertise
chenile-proxies answers:
- how a caller invokes one of those services through a Java interface
- whether the call should be routed locally or remotely
- how request and response conversion should happen
Together, they let an application depend on a service interface instead of hand-writing HTTP client code.
Module roles
chenile-service-registry
Modules:
service-registry-apiservice-registry-serviceservice-registry-delegate
Responsibilities:
service-registry-apicontainsChenileRemoteServiceDefinition,ChenileRemoteOperationDefinition,ServiceRegistryService, and the local near-cache.service-registry-servicehosts the registry, persists definitions, and publishes local Chenile services into the registry at startup.service-registry-delegateis the client-side delegate that talks to a remote registry endpoint and maintains a local cache of remote definitions.
chenile-proxies
Modules:
chenile-proxy
Responsibilities:
ProxyBuildercreates a Java proxy for a Chenile service interface.ProxyUtilslooks up remote service definitions and operation definitions from the registry.RemoteProxyInvokerperforms the actual remote invocation.ResponseBodyTypeSelectorreconstructs the correctGenericResponse<T>type for remote calls using service-registry metadata.
End-to-end flow
Server side
- The server hosts
service-registry-service. - On startup,
ServiceRegistryInitializerwalks the local Chenile configuration and saves each service definition. - Those definitions include:
- service id
- version
- base URL
- operation URLs
- output type metadata
Client side
- The client includes
service-registry-delegate. RemoteServiceRegistryInitializercan publish local client services to a remote registry if needed.ServiceRegistryClientImplreads remote definitions from the server-side registry and caches them locally.ProxyBuilderuses those definitions to create an interface-based proxy.- Business code calls the Java interface, not HTTP.
Configuration needed
Server package
The server must include the hosted registry service:
<dependency>
<groupId>org.chenile</groupId>
<artifactId>service-registry-service</artifactId>
</dependency>
And the Spring application must scan:
org.chenile.service.registry.configuration
Client package
The client must include:
<dependency>
<groupId>org.chenile</groupId>
<artifactId>service-registry-delegate</artifactId>
</dependency>
<dependency>
<groupId>org.chenile</groupId>
<artifactId>chenile-proxy</artifactId>
</dependency>
The client must also know where the remote registry is hosted:
chenile:
remote:
service:
registry: http://localhost:8000
Read-only packages
Set this property in a package that must consume registry metadata without publishing any of its locally declared services:
chenile:
service:
registry:
read-only: true
Read-only mode defaults to false. When enabled, both registry startup
initializers continue to load and cache existing definitions but do not publish
the package’s Chenile services. The delegate also rejects a direct
ServiceRegistryService.save(...) call before it sends an HTTP request.
This is a package-level policy. It complements, rather than replaces,
@ChenileController(registerInServiceRegistry = false), which suppresses one
specific service while publication remains enabled for the package.
Replacing RestClient with Chenile proxy
Before
The direct HTTP approach hard-codes URL structure and response parsing in application code.
Example pattern:
restClient.post()
.uri("/case-history")
.body(entry)
.retrieve()
.toBodilessEntity();
And:
restClient.get()
.uri("/case-history/{caseId}", caseId)
.retrieve()
.body(CASE_HISTORY_LIST_RESPONSE);
Problems with this style:
- URL knowledge is duplicated in the client
- response typing is manual
- transport details leak into business code
- moving a service between local and remote invocation requires client rewrites
After
Define and depend on the service interface:
- CaseHistoryService.java
Create a proxy bean:
@Bean
CaseHistoryService caseHistoryService(ProxyBuilder proxyBuilder) {
return proxyBuilder.buildProxy(CaseHistoryService.class, "caseHistoryService", null);
}
Then business code becomes:
caseHistoryService.save(entry);
List<CaseHistoryEntry> entries = caseHistoryService.retrieve(caseId);
This is exactly the pattern now used by:
- AiModelConfiguration.java
- CaseMemoryService.java
What the proxy needs
For ProxyBuilder to work, the service must be present in the registry with a Chenile service id.
In the casehistory example:
- the interface is
CaseHistoryService - the Chenile controller is registered as service id
caseHistoryService
See:
- CaseHistoryController.java
Specifically:
@ChenileController(value = "caseHistoryService", serviceName = "_caseHistoryService_")
The proxy bean must use the same service id:
proxyBuilder.buildProxy(CaseHistoryService.class, "caseHistoryService", null)
How response typing works
Remote Chenile calls return GenericResponse<T>.
The proxy layer reconstructs T from service-registry metadata.
That is handled in:
This is why the client can call:
List<CaseHistoryEntry> entries = caseHistoryService.retrieve(caseId);
without hand-writing a ParameterizedTypeReference.
When to keep RestClient
Use a Chenile proxy when:
- the target is a Chenile service
- the target is registered in the service registry
- you want interface-based invocation
- you want to hide transport details from business code
Use RestClient when:
- the remote system is not a Chenile service
- you need a one-off external API client
- the service contract is not represented as a shared Java interface
Migration checklist
- Move the target contract into a shared API module.
- Host the target service through a normal Chenile controller and service id.
- Include
service-registry-serviceon the server. - Include
service-registry-delegateandchenile-proxyon the client. - Point
chenile.remote.service.registryto the server. - Set
chenile.service.registry.read-only=trueif the client must only read registry metadata. - Create a proxy bean with
ProxyBuilder. - Replace
RestClientcode with the shared interface. - Remove manual URL and response-type handling from business services.
Start here
Client-side interceptors and proxy modes
Added on chenile.org; not in the repo copy of this guide.
- Building a proxy.
proxyBuilder.buildProxy(TargetService.class, "targetService", headerCopier[, ProxyMode])returns an object that implements the target interface. TheHeaderCopierdecides which headers of the current request travel with the call; the usual one copies everyx-header from theContextContainer. - Proxy modes.
ProxyMode.LOCAL,REMOTEorCOMPUTE_DYNAMICALLY(the default).ProxyTypeRoutermakes the dynamic choice: local (LocalProxyInvoker, in process) when the target’s monolith name equals this deployable’schenile.monolith.name, otherwise remote (RemoteProxyInvoker, over HTTP withHttpInvoker, or as an event throughChenilePub). - Client processors. A remote call runs a client-side chain against a
RemoteChenileExchange: an exception handler, then the processors named for the service and the operation (ServiceSpecificClientProcessorsInterpolation,OperationSpecificClientProcessorsInterpolation), then response typing (ResponseBodyTypeSelector) andChenileResponseHandler, which turns an error body back into anErrorNumExceptionwith the same code and description.
org.chenile.proxy.builder.ProxyBuilder, invoker.ProxyTypeRouter, LocalProxyInvoker / RemoteProxyInvoker, interceptors.HttpInvoker, ChenileResponseHandler, and the client-processor interpolations. Registry: ChenileRemoteServiceDefinition, ServiceRegistryService, ServiceRegistryClientImpl. Ships in chenile-proxies and chenile-service-registry.