Added multiserve support
This commit is contained in:
parent
c1e50126c9
commit
ccb3cc9ed2
3 changed files with 52 additions and 0 deletions
9
.vscode/launch.json
vendored
9
.vscode/launch.json
vendored
|
@ -9,6 +9,15 @@
|
|||
"debugSettings": "${command.debugSettings}",
|
||||
"program": "${workspaceRoot}/bin/server.dart",
|
||||
"args": []
|
||||
},
|
||||
{
|
||||
"name": "Start Multiserver",
|
||||
"type": "dart-cli",
|
||||
"request": "launch",
|
||||
"cwd": "${workspaceRoot}",
|
||||
"debugSettings": "${command.debugSettings}",
|
||||
"program": "${workspaceRoot}/bin/multi_server.dart",
|
||||
"args": []
|
||||
}
|
||||
]
|
||||
}
|
42
bin/multi_server.dart
Normal file
42
bin/multi_server.dart
Normal file
|
@ -0,0 +1,42 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:angel_multiserver/angel_multiserver.dart';
|
||||
|
||||
final Uri cluster = Platform.script.resolve('cluster.dart');
|
||||
final errorPage = GZIP.encode(UTF8.encode('''
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>503 Service Unavailable</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>503 Service Unavailable</h1>
|
||||
<i>There is no server available to service your request.</i>
|
||||
</body>
|
||||
</html>
|
||||
'''));
|
||||
|
||||
main() async {
|
||||
var loadBalancer = new LoadBalancer();
|
||||
await loadBalancer.spawnIsolates(cluster, count: 3);
|
||||
|
||||
loadBalancer
|
||||
..onCrash.listen((_) {
|
||||
// Auto-spawn a new instance on crash
|
||||
loadBalancer.spawnIsolates(cluster);
|
||||
})
|
||||
..onUnavailable.listen((socket) async {
|
||||
socket
|
||||
..writeln('HTTP/1.1 503 Service Unavailable')
|
||||
..writeln(HttpDate.format(new DateTime.now()))
|
||||
..writeln('Content-Encoding: gzip')
|
||||
..writeln()
|
||||
..add(errorPage)
|
||||
..writeln();
|
||||
await socket.close();
|
||||
});
|
||||
|
||||
var server = await loadBalancer.startServer();
|
||||
print(
|
||||
'Load balancer listening at http://${server.address.address}:${server.port}');
|
||||
}
|
|
@ -7,6 +7,7 @@ homepage: https://github.com/angel-dart/angel
|
|||
dependencies:
|
||||
angel_common: ^1.0.0-alpha
|
||||
angel_configuration: ^1.0.0
|
||||
angel_multiserver: ^1.0.0-dev
|
||||
mailer: ^1.1.0+4
|
||||
validate: ^1.5.2
|
||||
dev_dependencies:
|
||||
|
|
Loading…
Reference in a new issue