123123213weqw opened a new pull request, #10608:
URL: https://github.com/apache/rocketmq/pull/10608

   ## What is the purpose of the change
   
   Fixes #9341.
   
   `NamespaceV2` does not isolate resources: a consumer in one namespace can 
consume messages produced by a producer in a different namespace.
   
   ## Brief changelog
   
   `namespaceV2` was designed to be resolved server-side — the client attaches 
`nsd`/`ns` extension fields to each remoting request through 
`NamespaceRpcHook`, expecting the server to wrap the resource. However, the 
broker never reads those fields; it derives the namespace from the 
(already-wrapped) resource name via `NamespaceUtil.getNamespaceFromResource`. 
Meanwhile, all client-side resource wrapping (`ClientConfig.withNamespace` / 
`withoutNamespace` and their call sites in the producer/consumer) is driven by 
`ClientConfig.getNamespace()`, which only returns the deprecated V1 `namespace` 
and therefore stays empty when only `namespaceV2` is configured. The net effect 
is that neither side wraps the resource, so producers and consumers in 
different namespaces hit the same physical topic.
   
   This change makes `ClientConfig.getNamespace()` fall back to `namespaceV2` 
when the V1 `namespace` is not set (the V1 namespace still takes precedence 
when both are configured). Because `getNamespace()` is the single source of 
truth used by every resource wrapping/unwrapping call site, topics and groups 
are now correctly prefixed with the `namespaceV2` value, restoring isolation:
   
   - Producer (`namespaceV2 = InstanceTest1`) → `InstanceTest1%NAMESPACE_TOPIC`
   - Consumer (`namespaceV2 = InstanceTest`) → `InstanceTest%NAMESPACE_TOPIC`
   
   `NamespaceUtil.wrapNamespace` is idempotent (`isAlreadyWithNamespace`), so 
this is safe both for the direct-to-broker path (which ignores `nsd`/`ns`) and 
for a proxy that performs its own resolution.
   
   ## Verifying this change
   
   Added unit tests in `client/.../ClientConfigTest`:
   
   - `getNamespace()` returns `namespaceV2` when the V1 namespace is unset.
   - `withNamespace` / `withoutNamespace` wrap and unwrap using `namespaceV2`, 
and wrapping is idempotent.
   - The V1 `namespace` takes precedence over `namespaceV2` when both are set.
   
   ## Does this pull request potentially affect one of the following parts
   
   - Dependencies: No
   - Broker: No
   - Client: Yes — `ClientConfig.getNamespace()` now falls back to 
`namespaceV2` for resource wrapping when the V1 namespace is unset.
   - Consumer (pull/push): No code change beyond the shared `ClientConfig` 
behavior.
   - Namesrv: No
   - Proxy: No
   
   ## Documentation
   
   - Does this pull request introduce a new feature? No


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to