Skip to content

Commit

Permalink
add TCP transporter to resolver.
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed Feb 27, 2018
1 parent 84ceb21 commit 89c0073
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/service-broker.js
Expand Up @@ -241,6 +241,8 @@ class ServiceBroker {
TransporterClass = Transporters.Kafka;
else if (opt.startsWith("stan://"))
TransporterClass = Transporters.STAN;
else if (opt.startsWith("tcp://"))
TransporterClass = Transporters.TCP;

if (TransporterClass)
return new TransporterClass(opt);
Expand Down
39 changes: 39 additions & 0 deletions test/unit/service-broker.spec.js
Expand Up @@ -440,6 +440,45 @@ describe("Test option resolvers", () => {
"url": "stan://localhost:4222"
});
});

it("should resolve TcpTransporter from connection string", () => {
let trans = broker._resolveTransporter("tcp://192.168.0.100:6000");
expect(trans).toBeInstanceOf(Transporters.TCP);
expect(trans.opts.urls).toBe("tcp://192.168.0.100:6000");
});

it("should resolve TcpTransporter from string", () => {
let trans = broker._resolveTransporter("TCP");
expect(trans).toBeInstanceOf(Transporters.TCP);
});

it("should resolve TcpTransporter from obj without type", () => {
let options = {
port: 1234,
udpPeriod: 5,
udpBroadcast: true,
udpBindAddress: "192.168.0.100"
};
let trans = broker._resolveTransporter({ type: "TCP", options });
expect(trans).toBeInstanceOf(Transporters.TCP);
expect(trans.opts).toEqual({
"gossipPeriod": 2,
"maxConnections": 32,
"maxPacketSize": 1048576,
"port": 1234,
"udpBindAddress": "192.168.0.100",
"udpBroadcast": true,
"udpDiscovery": true,
"udpMaxDiscovery": 0,
"udpMulticast": "239.0.0.0",
"udpMulticastTTL": 1,
"udpPeriod": 5,
"udpPort": 4445,
"udpReuseAddr": true,
"urls": null,
"useHostname": true
});
});
});

describe("Test _resolveCacher", () => {
Expand Down

0 comments on commit 89c0073

Please sign in to comment.