第一步:TM修改
JoinGroupExecuteService修改
//源码
// transactionManager.join(dtxContext, joinGroupParams.getUnitId(), joinGroupParams.getUnitType(),
// rpcClient.getAppName(transactionCmd.getRemoteKey()), joinGroupParams.getTransactionState());
//修改成如下
transactionManager.join(dtxContext, joinGroupParams.getUnitId(), joinGroupParams.getUnitType(),
rpcClient.getModId(transactionCmd.getRemoteKey()), joinGroupParams.getTransactionState());
第二步:修改RpcClient抽象增加新的抽象方法
/**
* 获取应用ID,解决多节点返回错误的问题
* @param remoteKey
* @return
*/
public abstract String getModId(String remoteKey);
第三步:增加对该方法的实现:NettyRpcClient类(tx-msg-netty模块)
@Override
public String getModId(String remoteKey) {
return SocketManager.getInstance().getModuleId(remoteKey);
}
同时修改remoteKeys方法
@Override
public List<String> remoteKeys(String moduleName) {
return SocketManager.getInstance().remoteKeys(moduleName);
}
第四步:修改SocketManager类(tx-msg-netty模块),removeKeys方法注释掉(这个应该是作者写错),增加以下方法
// /**,
// * 获取模块的远程标识keys
// *
// * @param moduleName 模块名称
// * @return remoteKeys
// */
// @Deprecated
// public List<String> removeKeys(String moduleName) {
// List<String> allKeys = new ArrayList<>();
// for (Channel channel : channels) {
// if (moduleName.equals(getModuleName(channel))) {
// allKeys.add(channel.remoteAddress().toString());
// }
// }
// return allKeys;
// }
/**
* 获取模块的远程标识keys
*
* @param modId 模块唯一识别Id
* @return remoteKeys
*/
public List<String> remoteKeys(String modId) {
List<String> allKeys = new ArrayList<>();
for (Channel channel : channels) {
if (modId.equals(getModuleIdFromChannel(channel))) {
allKeys.add(channel.remoteAddress().toString());
}
}
return allKeys;
}
/**
* 获取模块名称
*
* @param channel 管道信息
* @return 模块名称
*/
public String getModuleIdFromChannel(Channel channel) {
String key = channel.remoteAddress().toString();
return getModuleId(key);
}
/**
* 获取模块的唯一ID
*
* @param remoteKey 远程唯一标识
* @return 模块名称
*/
public String getModuleId(String remoteKey) {
AppInfo appInfo = appNames.get(remoteKey);
return appInfo == null ? null : appInfo.getLabelName();
}
第五步:修改TC模块,增加以下配置类
@Component
public class ServerConfig implements ApplicationListener<WebServerInitializedEvent> {
private int serverPort;
public String getServerID() {
InetAddress address = null;
try {
address = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
e.printStackTrace();
}
return "http://"+address.getHostAddress() + ":" + this.serverPort;
}
@Override
public void onApplicationEvent(WebServerInitializedEvent event) {
this.serverPort = event.getWebServer().getPort();
}
}
@Component
public class MyModIdProvider implements ModIdProvider {
@Autowired
private ServerConfig serverConfig;
public String getSeverID() {
return serverConfig.getServerID();
}
@Override
public String modId(){
return getSeverID();
}
}
第六步:修改版本,上传私服,修改项目中的版本引用
mvn deploy:deploy-file -DgroupId=com.codingapi.txlcn -DartifactId=txlcn-common -Dversion=5.0.3.RELEASE -Dpackaging=jar -Dfile=txlcn-common-5.0.3.RELEASE.jar -DpomFile=txlcn-common.xml -Durl=http://39.107.96.206:38081/repository/weCode/ -DrepositoryId=weCode
mvn deploy:deploy-file -DgroupId=com.codingapi.txlcn -DartifactId=txlcn-logger -Dversion=5.0.3.RELEASE -Dpackaging=jar -Dfile=txlcn-logger-5.0.3.RELEASE.jar -DpomFile=txlcn-logger.xml -Durl=http://XXX/repository/weCode/ -DrepositoryId=weCode
mvn deploy:deploy-file -DgroupId=com.codingapi.txlcn -DartifactId=txlcn-tc -Dversion=5.0.3.RELEASE -Dpackaging=jar -Dfile=txlcn-tc-5.0.3.RELEASE.jar -DpomFile=txlcn-tc.xml -Durl=http://XXX/repository/weCode/ -DrepositoryId=weCode
mvn deploy:deploy-file -DgroupId=com.codingapi.txlcn -DartifactId=txlcn-tm -Dversion=5.0.3.RELEASE -Dpackaging=jar -Dfile=txlcn-tm-5.0.3.RELEASE.jar -DpomFile=txlcn-tm.xml -Durl=http://XXX/repository/weCode/ -DrepositoryId=weCode
mvn deploy:deploy-file -DgroupId=com.codingapi.txlcn -DartifactId=txlcn-tracing -Dversion=5.0.3.RELEASE -Dpackaging=jar -Dfile=txlcn-tracing-5.0.3.RELEASE.jar -DpomFile=txlcn-tracing.xml -Durl=http://XXX/repository/weCode/ -DrepositoryId=weCode
mvn deploy:deploy-file -DgroupId=com.codingapi.txlcn -DartifactId=txlcn-txmsg -Dversion=5.0.3.RELEASE -Dpackaging=jar -Dfile=txlcn-txmsg-5.0.3.RELEASE.jar -DpomFile=txlcn-txmsg.xml -Durl=http://XXX/repository/weCode/ -DrepositoryId=weCode
mvn deploy:deploy-file -DgroupId=com.codingapi.txlcn -DartifactId=txlcn-txmsg-netty -Dversion=5.0.3.RELEASE -Dpackaging=jar -Dfile=txlcn-txmsg-netty-5.0.3.RELEASE.jar -DpomFile=txlcn-txmsg-netty.xml -Durl=http://XXX/repository/weCode/ -DrepositoryId=weCode