new Router(id, optionopt)
Router class. Route messages between brokers over direct TCP connections.
Parameters:
| Name | Type | Attributes | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
id |
string | A unique broker ID. |
|||||||||
option |
object |
<optional> |
Options. Properties
|
Methods
listen(hostopt) → {Promise}
Start listening for incoming connections.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
host |
string |
<optional> |
Local IP address. If not given, the router will listen |
Returns:
Returns a promise. Resolved value will be the local port
number assigned by underlying OS. Therefore, EADDRINUSE will not occur.
- Type
- Promise
request(address) → {Promise}
Send a request to remote broker.
If no connection is available with the specified remote broker, it will
first establish a TCP connection, then send the data. If the connection
exists and the specified remote address/port match, it will reuse the
connection to send the data.
Parameters:
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
address |
object | Destination address of the broker. Properties
|
Returns:
Returns a Promise. The promise will be resolved
when the operation successfully writes the data into the underlying
socket.
- Type
- Promise