-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathin_memory_router.dart
40 lines (29 loc) · 1.36 KB
/
in_memory_router.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import "package:xconn/src/types.dart";
import "package:xconn/xconn.dart";
const procedureName = "io.xconn.example_procedure";
const topicName = "io.xconn.example_topic";
void main() async {
var router = Router()..addRealm("realm1");
var serializer = JSONSerializer();
var clientSideBase = ClientSideLocalBaseSession(1, "realm1", "local", "local", serializer, router);
var serverSideBase = ServerSideLocalBaseSession(1, "realm1", "local", "local", serializer, other: clientSideBase);
router.attachClient(serverSideBase);
var session = Session(clientSideBase);
// register a procedure
var registration = await session.register(procedureName, (inv) {
return Result(args: inv.args, kwargs: inv.kwargs, details: inv.details);
});
// call a procedure
var result = await session.call(procedureName, args: ["abc"]);
print("Result: args=${result.args}, kwargs=${result.kwargs}, details=${result.details}");
// unregister a procedure
await session.unregister(registration);
// subscribe to a topic
var subscription = await session.subscribe(topicName, (event) {
print("Event: args=${event.args}, kwargs=${event.kwargs}, details=${event.details}");
});
// publish to a topic
await session.publish(topicName, args: ["abc"], kwargs: {"one": 1}, options: {"acknowledge": true});
// unsubscribe from a topic
await session.unsubscribe(subscription);
}