You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eventmesh.apache.org by mi...@apache.org on 2021/08/02 08:30:32 UTC

[incubator-eventmesh] branch develop updated: [ISSUE #476] Biz Exceptions occured in EventMesh cause connection close of client (#477)

This is an automated email from the ASF dual-hosted git repository.

mikexue pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-eventmesh.git


The following commit(s) were added to refs/heads/develop by this push:
     new 05e3421  [ISSUE #476] Biz Exceptions occured in EventMesh cause connection close of client  (#477)
05e3421 is described below

commit 05e342158fe1f01234e5db44b06d1a646415b4fb
Author: lrhkobe <34...@users.noreply.github.com>
AuthorDate: Mon Aug 2 16:30:25 2021 +0800

    [ISSUE #476] Biz Exceptions occured in EventMesh cause connection close of client  (#477)
    
    * modify:optimize flow control in downstreaming msg
    
    * modify:optimize stategy of selecting session in downstream msg
    
    * modify:optimize msg downstream,msg store in session
    
    * modify:fix bug:not a @Sharable handler
    
    * modify:downstream broadcast msg asynchronously
    
    * modify:remove unneccessary interface in eventmesh-connector-api
    
    * modify:fix conflict
    
    * modify:add license in EventMeshAction
    
    * modify:fix ack problem
    
    * modify:fix exception handle when exception occured in EventMeshTcpMessageDispatcher
    
    * modify:fix log print
    
    close #476
---
 .../tcp/client/EventMeshTcpMessageDispatcher.java  | 46 +++++++++++++++++++---
 1 file changed, 41 insertions(+), 5 deletions(-)

diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/EventMeshTcpMessageDispatcher.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/EventMeshTcpMessageDispatcher.java
index cbe74f4..4d68ba8 100644
--- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/EventMeshTcpMessageDispatcher.java
+++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/EventMeshTcpMessageDispatcher.java
@@ -20,8 +20,7 @@ package org.apache.eventmesh.runtime.core.protocol.tcp.client;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.SimpleChannelInboundHandler;
 
-import org.apache.eventmesh.common.protocol.tcp.Command;
-import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage;
+import org.apache.eventmesh.common.protocol.tcp.*;
 import org.apache.eventmesh.common.protocol.tcp.Package;
 import org.apache.eventmesh.runtime.boot.EventMeshTCPServer;
 import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.SessionState;
@@ -76,9 +75,46 @@ public class EventMeshTcpMessageDispatcher extends SimpleChannelInboundHandler<P
 
             dispatch(ctx, pkg, startTime, cmd);
         } catch (Exception e) {
-            logger.error("exception occurred while pkg|cmd={}|pkg={}|errMsg={}", cmd, pkg, e);
-            //throw new RuntimeException(e);
-            throw e;
+            logger.error("exception occurred while pkg|cmd={}|pkg={}", cmd, pkg, e);
+            writeToClient(cmd, pkg, ctx, e);
+        }
+    }
+
+    private void writeToClient(Command cmd, Package pkg, ChannelHandlerContext ctx, Exception e){
+        try{
+            Package res = new Package();
+            res.setHeader(new Header(getReplyCommand(cmd), OPStatus.FAIL.getCode(), e.toString(), pkg.getHeader()
+                    .getSeq()));
+            ctx.writeAndFlush(res);
+        }catch (Exception ex){
+            logger.warn("writeToClient failed", ex);
+        }
+    }
+
+    private Command getReplyCommand(Command cmd){
+        switch (cmd) {
+            case HELLO_REQUEST:
+                return Command.HELLO_RESPONSE;
+            case RECOMMEND_REQUEST:
+                return Command.RECOMMEND_RESPONSE;
+            case HEARTBEAT_REQUEST:
+                return Command.HEARTBEAT_RESPONSE;
+            case SUBSCRIBE_REQUEST:
+                return Command.SUBSCRIBE_RESPONSE;
+            case UNSUBSCRIBE_REQUEST:
+                return Command.UNSUBSCRIBE_RESPONSE;
+            case LISTEN_REQUEST:
+                return Command.LISTEN_RESPONSE;
+            case CLIENT_GOODBYE_REQUEST:
+                return Command.CLIENT_GOODBYE_RESPONSE;
+            case REQUEST_TO_SERVER:
+                return Command.RESPONSE_TO_CLIENT;
+            case ASYNC_MESSAGE_TO_SERVER:
+                return Command.ASYNC_MESSAGE_TO_SERVER_ACK;
+            case BROADCAST_MESSAGE_TO_SERVER:
+                return Command.BROADCAST_MESSAGE_TO_SERVER_ACK;
+            default:
+                return cmd;
         }
     }
 

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: commits-help@eventmesh.apache.org