1 | # Transports
|
2 |
|
3 | Evejs has the following built-in transports:
|
4 |
|
5 | - [AMQP](#amqp)
|
6 | - [Distribus](#distribus)
|
7 | - [HTTP](#http)
|
8 | - [Local](#local)
|
9 | - [PubNub](#pubnub)
|
10 | - [WebSocket](#websocket)
|
11 |
|
12 |
|
13 | ## AMQP
|
14 |
|
15 | To configure an AMQP transport:
|
16 |
|
17 | ```js
|
18 | eve.system.init({
|
19 | transports: [
|
20 | {
|
21 | type: 'amqp',
|
22 | id: 'myAmqp', // optional identifier for the transport
|
23 | url: 'amqp://localhost', // specify either url or host
|
24 | host: 'dev.rabbitmq.com' // specify either url or host
|
25 | }
|
26 | ]
|
27 | });
|
28 | ```
|
29 |
|
30 | Available properties:
|
31 |
|
32 | - `type: 'amqp'`
|
33 | Required. Specifies the type of transport.
|
34 | - `id: string`
|
35 | Optional.
|
36 | - `url: string`
|
37 | The url of an AMQP server. Either `url` or `host` must be specified.
|
38 | - `host: string`
|
39 | The host address of an AMQP server. Either `url` or `host` must be specified.
|
40 |
|
41 |
|
42 | ## Distribus
|
43 |
|
44 | To configure a Distribus transport:
|
45 |
|
46 | ```js
|
47 | eve.system.init({
|
48 | transports: [
|
49 | {
|
50 | type: 'distribus',
|
51 | id: 'myDistribus', // optional identifier for the transport
|
52 | host: distribus.Host // instance of a distribus Host, or...
|
53 | port: number // ...a port number to start a new distribus host
|
54 | }
|
55 | ]
|
56 | });
|
57 | ```
|
58 |
|
59 | Available properties:
|
60 |
|
61 | - `type: 'distribus'`
|
62 | Required. Specifies the type of transport.
|
63 | - `id: string`
|
64 | Optional.
|
65 | - `host: distribus.Host`
|
66 | An instance of a distribus `Host`. Optional
|
67 | - `port: number`
|
68 | A port number used to initialize a new distribus `Host`. Optional.
|
69 |
|
70 | Either `host` or `port` can be configured. If none is provided, a local distribus `Host` is created.
|
71 |
|
72 |
|
73 | ## HTTP
|
74 |
|
75 | To use the HTTP transport with the Eve transport manager you define the type and its settings.
|
76 |
|
77 | ```js
|
78 | eve.system.init({
|
79 | transports: [
|
80 | {
|
81 | type: 'http',
|
82 | id: 'myAmqp', // optional identifier for the transport
|
83 | port: 3000,
|
84 | url: 'http://127.0.0.1:3000/agents/:id',
|
85 | remoteUrl: 'http://127.0.0.1:3000/agents/:id',
|
86 | localShortcut: false,
|
87 | }
|
88 | ]
|
89 | });
|
90 | ```
|
91 |
|
92 | Mandatory:
|
93 |
|
94 | - `type: 'http'`
|
95 | Required. The type is a mandatory field for the TransportManager to identify the specific transport you want to add. In this case it is 'http'.
|
96 | - `url: String`
|
97 | Required. This is the URL of the server. This is where and how incoming messages are received. The ':id' will be replaced with the agent id of the targeted agent.
|
98 | - `id: string`
|
99 | Optional. An id, used to find a specific transport by it's id in the ServiceManager.
|
100 | - `port: Number`
|
101 | Optional. The port number the HTTP server should listen on. This is optional **IF** you also define a port number in the `url`, which will then be parsed.
|
102 | - `remoteUrl: String`
|
103 | Optional. This field is optional. It is be used to automatically create an address. If you have agents "agent1" and "agent2" and you want to send a message from 1 to 2 using `agent1.send("agent2","hello!")` an error will be thrown if no remoteUrl is defined. By using the remoteUrl, an address (in this case http://127.0.0.1:3000/agents/agent1) will be generated. This is particularly useful if you're only using HTTP to bridge to one other platform or service.
|
104 | - `localShortcut: Boolean`
|
105 | Optional. This option when true, will check if the recipient of a message exists in the same server as the sender. If this is the case, the message is delivered locally, increasing performance. The default value is `true`.
|
106 |
|
107 |
|
108 | #### Local
|
109 |
|
110 | To configure a local transport:
|
111 |
|
112 | ```js
|
113 | eve.system.init({
|
114 | transports: [
|
115 | {
|
116 | type: 'local',
|
117 | id: 'myLocalTransport', // optional identifier for the transport
|
118 | }
|
119 | ]
|
120 | });
|
121 | ```
|
122 |
|
123 | Available properties:
|
124 |
|
125 | - `type: 'local'`
|
126 | Required. Specifies the type of transport.
|
127 | - `id: string`
|
128 | Optional.
|
129 |
|
130 |
|
131 | ## PubNub
|
132 |
|
133 | To configure a PubNub transport:
|
134 |
|
135 | ```js
|
136 | eve.system.init({
|
137 | transports: [
|
138 | {
|
139 | type: 'pubnub',
|
140 | id: 'myPubnub', // optional identifier for the transport
|
141 | publish_key: 'demo', // required
|
142 | subscribe_key: 'demo', // required
|
143 | }
|
144 | ]
|
145 | });
|
146 | ```
|
147 |
|
148 | Available properties:
|
149 |
|
150 | - `type: 'pubnub'`
|
151 | Required. Specifies the type of transport.
|
152 | - `id: string`
|
153 | Optional.
|
154 | - `publish_key: string`
|
155 | Required.
|
156 | - `subscribe_key: string`
|
157 | Required.
|
158 |
|
159 | A `publish_key` and `subscribe_key` can be acquired by creating an account at http://pubnub.com.
|
160 |
|
161 |
|
162 | ## WebSocket
|
163 |
|
164 | To configure a WebSocket transport:
|
165 |
|
166 | ```js
|
167 | eve.system.init({
|
168 | transports: [
|
169 | {
|
170 | type: 'ws',
|
171 | id: 'myWebSocket', // optional identifier
|
172 | url: 'ws://localhost:3000/agents/:id', // optional url with id placeholder
|
173 | localShortcut: true
|
174 | }
|
175 | ]
|
176 | });
|
177 | ```
|
178 |
|
179 | A WebSocket can be used both server side as well as client side (browser).
|
180 | When `url` is provided, a WebSocket server is started. and agents can connect to
|
181 | this server. When a WebSocket transport has no url, it cannot be as server but
|
182 | only as client, connecting to other servers. Once a connection is made between
|
183 | two agents, they can both send messages to each other.
|
184 |
|
185 | Available properties:
|
186 |
|
187 | - `type: 'ws'`
|
188 | Required. Specifies the type of transport.
|
189 | - `id: string`
|
190 | Optional identifier for this transport.
|
191 | - `url: string`
|
192 | Optional. If provided, A WebSocket server is started on given url.
|
193 | The url must contain a `:id` placeholder to build urls for individual agents.
|
194 | Example: `'ws://localhost:3000/agents/:id'`.
|
195 | - `localShortcut: boolean`
|
196 | Optional. If true, messages to local agents are not send via WebSocket but
|
197 | delivered immediately. Setting `localShortcut` to `false` can be useful for
|
198 | debugging and testing purposes.
|