vert-x3 / vertx-tcp-eventbus-bridge

Apache License 2.0
49 stars 44 forks source link

Is it possible that this bridge replays old messages ? #2

Closed ramukima closed 8 years ago

ramukima commented 8 years ago

Server

package test;

import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.bridge.BridgeOptions;
import io.vertx.ext.bridge.PermittedOptions;
import io.vertx.ext.eventbus.bridge.tcp.TcpEventBusBridge;

public class BridgeTest {
    public static void main(String[] args) {
        Vertx vertx = Vertx.vertx();
        TcpEventBusBridge bridge = TcpEventBusBridge.create(
                vertx,
                new BridgeOptions()
                .addOutboundPermitted(new PermittedOptions().setAddress("out")));
        bridge.listen(7000, res -> vertx.setPeriodic(2*1000, new Handler<Long>() {
            @Override
            public void handle(Long timer) {
                vertx.eventBus().send("out", new JsonObject().put("now", System.currentTimeMillis()));
            }
        }));
    }
}

Client

var EventBus = require('../lib/tcp-vertx-eventbus');
    var eb = new EventBus('localhost', 7000);
    eb.onerror = function (err) {
      console.error(err);
    };

    eb.onopen = function () {
      // send a echo message
      eb.registerHandler("out", function (err, msg) {
          console.log("message:" + JSON.stringify(msg));
      });
    };

Result

bash-3.2$ node test/app.js 
message:{"type":"message","address":"out","headers":{},"body":{"now":1453190899736}}
message:{"type":"message","address":"out","headers":{},"body":{"now":1453190899736}}
message:{"type":"message","address":"out","headers":{},"body":{"now":1453190899736}}
message:{"type":"message","address":"out","headers":{},"body":{"now":1453190899736}}
message:{"type":"message","address":"out","headers":{},"body":{"now":1453190899736}}

Notice the value of 'now' in the message received by the client.

ramukima commented 8 years ago

Verified. Works now, thanks for fixing this.