One call, near or far
Service order-service depends on service inventory-service through its interface. A Chenile proxy decides at runtime whether inventory-service lives in the same mini monolith or in another one, carries the caller's headers across, runs the right interceptors, and hands back a result or an exception that looks the same either way.
Headers
Payload and parameters
What happens on the way
1 · The registry says where inventory-service lives
Every deployable publishes its services to the service registry, a separate deployable, when it starts: the service id and version, the monolithName, the baseUrl, every operation's URL, HTTP method and parameters, and the client interceptors callers should run. On its first call the proxy fetches inventory-service's entry and keeps it in a near cache.
2 · The router picks local or remote
ProxyTypeRouter compares inventory-service's monolithName with this deployable's chenile.monolith.name. The same name means local; a different one means remote. Moving inventory-service to another mini monolith changes the answer without changing order-service.
3 · Near interceptors run on the caller's side
For a remote call the proxy runs its own chain in order-service's deployable: an exception handler, the operation and service client interceptors named in inventory-service's registry entry, a response type selector and HttpInvoker. A local call skips them: there is no network call to retry, time or translate.
4 · Far interceptors always run
inventory-service's own chenile-highway runs on every call. Locally, LocalProxyInvoker calls ChenileEntryPoint in process. Remotely, inventory-service's HttpEntryPoint in the other mini monolith runs it. Either way inventory-service's policies apply.
What crosses from the near side to the far side
The proxy is built with a HeaderCopier. The usual one, PopulateContextContainer, copies every x- header from order-service's ContextContainer, which order-service's own highway filled from the incoming request.
Always carried
Every x- header in order-service's context: tenant (x-chenile-tenant-id), user, trajectory, x-request-id, x-Authorization and the rest. So inventory-service runs for the same tenant, user and trajectory as order-service.
Parameters
The method's arguments are bound by inventory-service's parameter definitions: HEADER parameters become headers (and fill path variables in the URL), the BODY parameter becomes the body. Locally the body object is passed as is; remotely it is sent as JSON and typed again in inventory-service's highway.
Added for remote calls
x-chenile-entry-point-sub-type: REMOTE_PROXY, Authorization copied from x-Authorization, and JSON content headers. The URL is the registry's baseUrl plus the operation's URL.
order-service cannot tell near from far
Results
Locally the proxy returns the data from inventory-service's GenericResponse. Remotely the response body is read as GenericResponse<T>, using the operation's output type from the registry, and the proxy returns its payload. order-service gets the same object type either way.
Errors
Locally inventory-service's exception reaches order-service unchanged. Remotely ChenileResponseHandler reads the error body and throws an ErrorNumException with the same code, sub-error code and description. A connection failure becomes a ServerException (cannot connect or cannot invoke). Catch ErrorNumException and branch on its codes, and the same handler works for both.
Registry and proxies, the concept → Every transport adapter →