2017-03-26 2 views
0

저는 Vertex SockJs로 Eventbus Bridge를 구축했습니다. 이 ClientHtml의 코드SockJs Eventbus Bridge : Verticle을 다시 시작하면 ClientHtml을 다시 시작해야합니까?

@Override 
public void start() throws Exception { 
    Router router = Router.router(vertx); 

    SockJSHandler sockJSHandler = SockJSHandler.create(vertx); 
    BridgeOptions options = new BridgeOptions(); 

    options.addInboundPermitted(new PermittedOptions().setAddress("test")); 
    options.addOutboundPermitted(new PermittedOptions().setAddress("test")); 
    options.addInboundPermitted(new PermittedOptions().setAddress("test2")); 
    options.addOutboundPermitted(new PermittedOptions().setAddress("test2")); 

    sockJSHandler.bridge(options); 

    router.route("/eventbus/*").handler(sockJSHandler); 

    vertx.createHttpServer().requestHandler(router::accept).listen(8600); 

    vertx.setTimer(5000, id -> { 
     vertx.eventBus().send("test", "hallo!", async -> { 
      if (async.succeeded()) { 
       System.out.println("Success!"); 
      } else { 
       System.out.println("Failure!"); 
       System.out.println(async.cause()); 
      } 
     }); 
     System.out.println("SEND!"); 
    }); 

} 

입니다 :

내 verticle의 코드 지금

var eb = new EventBus('http://localhost:8600/eventbus'); 

eb.onError=function() { 
    console.log('error'); 
} 

eb.onopen = function() { 
    console.log('connected'); 
    // set a handler to receive a message 
    eb.registerHandler('test', function(error, message) { 
    console.log('received a message: ' + JSON.stringify(message)); 
    $("#text").html(JSON.stringify(message)); 
    }); 

    eb.registerHandler('test2', function(error, message) { 
     console.log('received a message: ' + JSON.stringify(message)); 
     console.log("Error: "+error); 
     $("#text2").html(JSON.stringify(message)); 
     }); 
} 

eb.onclose = function() { 
    console.log("disconnected"); 
    eb = null; 
}; 

무엇 임 우려에 대한 내 verticle가와의 연결을 생성

클라이언트, 모두 괜찮습니다. 그러나 Im이 나의 verticle Im을 재시동 할 때 NO_HANDLER 오류가 발생했을 때, Eventbus의 새로운 인스턴스가 없기 때문에? 이 문제를 처리 할 수있는 방법이 있습니까?

답변

2

페이지가로드 된 후 호출되는 메서드에 설치 코드를 입력 할 수 있습니다. onclose 콜백에서 모든 응답 핸들러를 정리하고 (서버 응답을받지 못함) 설정 메소드를 다시 호출하십시오. 또한

function setupEventBus() { 
    var eb = new EventBus(window.location.protocol + "//" + window.location.host + "/eventbus"); 
    eb.onclose = function (e) { 
    // Cleanup reply handlers 
    var replyHandlers = eb.replyHandlers; 
    for (var address in replyHandlers) { 
     if (replyHandlers.hasOwnProperty(address)) { 
     replyHandlers[address]({ 
      failureCode: -1, 
      failureType: "DISCONNECT", 
      message: "EventBus closed" 
     }); 
     } 
    } 
    // Setup the EventBus object again (after some time) 
    setTimeout(setupEventBus, 1000); 
    }; 
    eb.onopen = function() { 
    // Register your handlers here 
    }; 
} 
+0

, 당신은 https://github.com/vert-x3/issues/issues/152 – tsegismont

+0

은 감사 수행 할 수 있습니다이 GitHub의 문제가, 당신의 예는 나를 매우 도움이 !! : -))) – user3133542

관련 문제