Skip to content

Commit

Permalink
Update configs
Browse files Browse the repository at this point in the history
  • Loading branch information
bahung1221 committed Sep 23, 2019
1 parent 3d6071a commit 1622ba5
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 29 deletions.
1 change: 0 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
comma-style: [error, last],
eol-last: [error, always],
import/no-unresolved: off,
import/no-dynamic-require: off,
indent: [error, 2, { SwitchCase: 1 }],
global-require: off,
linebreak-style: [error, unix],
Expand Down
35 changes: 22 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,17 @@ const services = [
'services/bar.js',
]
const options = {
transporter: 'nats',
transporterOptions: {
servers: ['nats://demo.nats.io:4222'],
timeout: 3000,
pingInterval: 120000,
reconnect: true,
reconnectTimeWait: 2000,
maxReconnectAttempts: 10,
maxRequestRetryAttempts: 3,
transporter: {
name: 'nats',
options: {
servers: ['nats://demo.nats.io:4222'],
timeout: 3000,
pingInterval: 120000,
reconnect: true,
reconnectTimeWait: 2000,
maxReconnectAttempts: 10,
maxRequestRetryAttempts: 3,
},
},
}

Expand All @@ -75,10 +77,17 @@ just pass config to `Broker()` and then run `node services/bar.js`:
```javascript
const broker = require('microsia/broker')
const app = broker({
transporter: 'nats',
transporterOptions: {
servers: ['nats://demo.nats.io:4222'],
timeout: 3000,
transporter: {
name: 'nats',
options: {
servers: ['nats://demo.nats.io:4222'],
timeout: 3000,
pingInterval: 120000,
reconnect: true,
reconnectTimeWait: 2000,
maxReconnectAttempts: 10,
maxRequestRetryAttempts: 3,
},
},
}).createService({ name: 'bar' })

Expand Down
15 changes: 11 additions & 4 deletions example/gateway/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ const broker = require('../../broker') // Broker
const expressApp = express()
const port = 3000
const microApp = broker({
transporter: 'nats',
transporterOptions: {
servers: ['nats://demo.nats.io:4222'],
timeout: 3000,
transporter: {
name: 'nats',
options: {
servers: ['nats://demo.nats.io:4222'],
timeout: 3000,
pingInterval: 120000,
reconnect: true,
reconnectTimeWait: 2000,
maxReconnectAttempts: 10,
maxRequestRetryAttempts: 3,
},
},
}).createService({ name: 'gateway' })

Expand Down
20 changes: 11 additions & 9 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ const services = [
'services/bar.js',
]
const options = {
transporter: 'nats',
transporterOptions: {
servers: ['nats://demo.nats.io:4222'],
timeout: 3000,
pingInterval: 120000,
reconnect: true,
reconnectTimeWait: 2000,
maxReconnectAttempts: 10,
maxRequestRetryAttempts: 3,
transporter: {
name: 'nats',
options: {
servers: ['nats://demo.nats.io:4222'],
timeout: 3000,
pingInterval: 120000,
reconnect: true,
reconnectTimeWait: 2000,
maxReconnectAttempts: 10,
maxRequestRetryAttempts: 3,
},
},
}

Expand Down
5 changes: 3 additions & 2 deletions lib/broker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ const TRANSPORTERS = {
class Broker {
constructor(opt = {}) {
try {
this.TransporterClass = require(TRANSPORTERS[opt.transporter])
// eslint-disable-next-line import/no-dynamic-require, global-require
this.TransporterClass = require(TRANSPORTERS[opt.transporter.name])
} catch (e) {
// console.log('No valid trans was given => create only local transporter')
}
this.transporterOpt = { ...opt.transporterOptions }
this.transporterOpt = { ...opt.transporter.options }
this.transporter = null
this.localTransporter = null
this.services = new Map()
Expand Down
1 change: 1 addition & 0 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function loadServices(opt, arr) {

// Load all given services
arr.forEach((service) => {
// eslint-disable-next-line import/no-dynamic-require, global-require
require(path.join(process.cwd(), service))
})
}
Expand Down

0 comments on commit 1622ba5

Please sign in to comment.