You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@seata.apache.org by "funky-eyes (via GitHub)" <gi...@apache.org> on 2026/04/01 01:43:57 UTC

Re: [PR] feature: add UnregisterRM protocol to notify server on client destroy [incubator-seata]

funky-eyes commented on code in PR #8020:
URL: https://github.com/apache/incubator-seata/pull/8020#discussion_r3019314388


##########
core/src/main/java/org/apache/seata/core/rpc/netty/RmNettyRemotingClient.java:
##########
@@ -292,6 +300,59 @@ public void sendRegisterMessage(String serverAddress, Channel channel, String re
         }
     }
 
+    public void unregisterResource(String resourceGroupId, String resourceId) {
+        if (StringUtils.isBlank(transactionServiceGroup) || StringUtils.isBlank(resourceId)) {
+            return;
+        }
+        sendUnregisterToServers(resourceId);
+    }
+
+    private static final long UNREGISTER_FLUSH_TIMEOUT_MS = 1000;
+
+    private List<ChannelFuture> sendUnregisterToServers(String resourceIds) {
+        List<ChannelFuture> futures = new ArrayList<>();
+        try {
+            for (Map.Entry<String, Channel> entry :
+                    getClientChannelManager().getChannels().entrySet()) {
+                String serverAddress = entry.getKey();
+                Channel channel = entry.getValue();
+                if (!channel.isActive()) {
+                    continue;
+                }
+                String serverVersion = getClientChannelManager().getServerVersion(serverAddress);
+                if (serverVersion == null || !Version.isAboveOrEqualVersion260(serverVersion)) {
+                    LOGGER.warn(
+                            "Server {} does not support UnregisterRMRequest (version: {})",
+                            serverAddress,
+                            serverVersion);
+                    continue;
+                }
+                UnregisterRMRequest message = new UnregisterRMRequest(applicationId, transactionServiceGroup);
+                message.setResourceIds(resourceIds);
+                try {
+                    if (!channel.isWritable()) {
+                        throw new FrameworkException(
+                                "msg:" + message.toString(), FrameworkErrorCode.ChannelIsNotWritable);
+                    }
+                    RpcMessage rpcMessage = buildRequestMessage(message, ProtocolConstants.MSGTYPE_RESQUEST_ONEWAY);
+                    futures.add(channel.writeAndFlush(rpcMessage));

Review Comment:
   @WangzJi PTAL



-- 
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: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org