-
-
Notifications
You must be signed in to change notification settings - Fork 588
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into runner-esm
- Loading branch information
Showing
36 changed files
with
13,028 additions
and
14,171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
"use strict"; | ||
|
||
const ServiceBroker = require("../src/service-broker"); | ||
const Middlewares = require("../src/middlewares"); | ||
|
||
const broker1 = new ServiceBroker({ | ||
nodeID: "node-1", | ||
|
||
transporter: "TCP", | ||
|
||
registry: { | ||
discoverer: "Local" | ||
// discoverer: "Redis" | ||
// discoverer: "Etcd3" | ||
} | ||
|
||
// middlewares: [ | ||
// Middlewares.Debugging.TransitLogger({ | ||
// logPacketData: true, | ||
// folder: null, | ||
// colors: { | ||
// send: "magenta", | ||
// receive: "blue" | ||
// }, | ||
// packetFilter: ["HEARTBEAT"] | ||
// }) | ||
// ] | ||
}); | ||
|
||
const broker2 = new ServiceBroker({ | ||
nodeID: "node-2", | ||
|
||
transporter: "TCP", | ||
|
||
registry: { | ||
discoverer: "Local" | ||
// discoverer: "Redis", | ||
// discoverer: "Etcd3" | ||
} | ||
|
||
// middlewares: [ | ||
// Middlewares.Debugging.TransitLogger({ | ||
// logPacketData: true, | ||
// folder: null, | ||
// colors: { | ||
// send: "magenta", | ||
// receive: "blue" | ||
// }, | ||
// packetFilter: ["HEARTBEAT"] | ||
// }) | ||
// ] | ||
}); | ||
|
||
const locationSchema = { | ||
name: "location", | ||
|
||
// depends on device.service at node-2 | ||
dependencies: ["device"], | ||
|
||
async started() { | ||
this.logger.info("Location Services started"); | ||
} | ||
}; | ||
|
||
const tenantSchema = { | ||
name: "tenant", | ||
|
||
actions: { | ||
add: { | ||
handler(ctx) { | ||
return "tenant.add action"; | ||
} | ||
} | ||
}, | ||
|
||
async started() { | ||
this.logger.info("Tenant Services started"); | ||
} | ||
}; | ||
|
||
const assetSchema = { | ||
name: "device", | ||
|
||
// Depends on tenant.service located at node-1 | ||
dependencies: ["tenant"], | ||
|
||
async started() { | ||
this.logger.info("Device Services started"); | ||
|
||
const result = await this.broker.call("tenant.add"); | ||
|
||
this.logger.info("RESPONSE FROM TENANT =>", result); | ||
} | ||
}; | ||
|
||
// Place location.service and tenant.service at node-1 | ||
broker1.createService(locationSchema); | ||
broker1.createService(tenantSchema); | ||
|
||
// Place asset.service at node-2 | ||
broker2.createService(assetSchema); | ||
/*broker2.createService({ | ||
name: "test1", | ||
dependencies: ["location", "device"], | ||
started() { | ||
return this.Promise.delay(2000); | ||
} | ||
}); | ||
broker2.createService({ | ||
name: "test2", | ||
dependencies: ["location", "tenant"], | ||
started() { | ||
return this.Promise.delay(3000); | ||
} | ||
}); | ||
broker2.createService({ | ||
name: "test3", | ||
dependencies: ["tenant", "device"], | ||
started() { | ||
return this.Promise.delay(1000); | ||
} | ||
}); | ||
broker2.createService({ | ||
name: "test4", | ||
dependencies: ["test3"], | ||
started() { | ||
return this.Promise.delay(500); | ||
} | ||
}); | ||
broker2.createService({ | ||
name: "test5", | ||
started() { | ||
return this.Promise.delay(2500); | ||
} | ||
});*/ | ||
|
||
Promise.all([broker1.start(), broker2.start()]) | ||
.then(() => { | ||
broker1.repl(); | ||
}) | ||
.catch(err => console.log(err)); |
Oops, something went wrong.