|
1 |
| -# Coordination server |
| 1 | +# Coordination Server |
2 | 2 |
|
3 |
| -## Create the server |
| 3 | +## Creating the Server |
4 | 4 |
|
5 |
| -More about the server configuration options is [here](./index.md#coordination-server). |
| 5 | +> You can find the complete code for a server implementation example in the SDK repository under the `./examples/server` directory. |
| 6 | +
|
| 7 | +## Configuration |
| 8 | + |
| 9 | +Below is an example of the configuration and implementation for the protocol coordination server. |
| 10 | + |
| 11 | +To instantiate the server, you need to generate a peer key. The process of key generation is explained in detail [here](/#peer-key-generation). |
6 | 12 |
|
7 | 13 | ```typescript
|
8 |
| -import { ServerOptions, createServer, storage } from '@windingtree/sdk'; |
| 14 | +import { ServerOptions } from '@windingtree/sdk-server'; |
| 15 | +import { memoryStorage } from '@windingtree/sdk-storage'; |
| 16 | +import { serverPeerKey } from './path/to/config.js'; |
9 | 17 |
|
10 | 18 | const options: ServerOptions = {
|
11 |
| - messagesStorageInit: storage['YOUR_STORAGE_OPTION'] |
12 |
| - .createInitializer |
13 |
| - /** Your storage configuration */ |
14 |
| - (), |
15 |
| - /** Other server configuration options */ |
| 19 | + port: 33333, |
| 20 | + peerKey: serverPeerKey, |
| 21 | + /** |
| 22 | + * This example uses MemoryStorage, |
| 23 | + * but in production, it is recommended to use Redis. |
| 24 | + **/ |
| 25 | + messagesStorageInit: memoryStorage.createInitializer(), |
16 | 26 | };
|
| 27 | +``` |
| 28 | + |
| 29 | +For caching requests (clients' requests and suppliers' offers), the server uses storage. In this configuration example, we use the `memoryStorage` implementation offered by the SDK library. However, in your system, you are free to implement your own storage layer. For details, please see the [storage documentation](./storage.md). |
17 | 30 |
|
| 31 | +To create the server, you can use the `createServer` function from the `@windingtree/sdk-server` library, passing in the `options` object defined earlier. |
| 32 | + |
| 33 | +```typescript |
| 34 | +import { createServer } from '@windingtree/sdk-server'; |
| 35 | + |
| 36 | +// Using the `options` from the example above |
18 | 37 | const server = createServer(options);
|
19 | 38 |
|
20 | 39 | server.addEventListener('start', () => {
|
21 |
| - logger.trace('🚀 Server started at', new Date().toISOString()); |
| 40 | + console.log('🚀 Server started'); |
22 | 41 | });
|
23 | 42 |
|
24 | 43 | server.addEventListener('stop', () => {
|
25 |
| - logger.trace('👋 Server stopped at:', new Date().toISOString()); |
| 44 | + console.log('👋 Server stopped'); |
26 | 45 | });
|
27 | 46 |
|
28 | 47 | await server.start(); // Start the server
|
| 48 | + |
| 49 | +// ... |
29 | 50 | await server.stop(); // Stop the server
|
30 | 51 | ```
|
| 52 | + |
| 53 | +Once the server is started, it begins accepting connections from clients and supplier nodes and efficiently coordinates messages between them to facilitate seamless interactions within the protocol ecosystem. |
0 commit comments