Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #7699] Add namespace v2 in client #7700

Merged
merged 10 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add NamespaceRpcHook
  • Loading branch information
drpmma committed Dec 29, 2023
commit eef4774473dd35313686c0bf95279a9630a72ebc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.client.rpchook.NamespaceRpcHook;
import org.apache.rocketmq.common.BoundaryType;
import org.apache.rocketmq.common.MQVersion;
import org.apache.rocketmq.common.MixAll;
Expand Down Expand Up @@ -257,6 +258,7 @@ public MQClientAPIImpl(final NettyClientConfig nettyClientConfig,
this.remotingClient = new NettyRemotingClient(nettyClientConfig, channelEventListener);
this.clientRemotingProcessor = clientRemotingProcessor;

this.remotingClient.registerRPCHook(new NamespaceRpcHook(clientConfig));
// Inject stream rpc hook first to make reserve field signature
if (clientConfig.isEnableStreamRequestType()) {
this.remotingClient.registerRPCHook(new StreamTypeRPCHook());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.rocketmq.client.rpchook;

import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.client.ClientConfig;
import org.apache.rocketmq.remoting.CommandCustomHeader;
import org.apache.rocketmq.remoting.RPCHook;
import org.apache.rocketmq.remoting.protocol.RemotingCommand;
import org.apache.rocketmq.remoting.rpc.RpcRequestHeader;

public class NamespaceRpcHook implements RPCHook {
private final ClientConfig clientConfig;

public NamespaceRpcHook(ClientConfig clientConfig) {
this.clientConfig = clientConfig;
}

@Override
public void doBeforeRequest(String remoteAddr, RemotingCommand request) {
CommandCustomHeader customHeader = request.readCustomHeader();
if (customHeader instanceof RpcRequestHeader) {
RpcRequestHeader requestHeader = (RpcRequestHeader) customHeader;
if (StringUtils.isNotEmpty(clientConfig.getNamespaceV2())) {
requestHeader.setNamespaced(true);
requestHeader.setNamespace(clientConfig.getNamespaceV2());
}
}
}

@Override
public void doAfterResponse(String remoteAddr, RemotingCommand request,
RemotingCommand response) {

}
}