-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjulia.qmd
122 lines (85 loc) · 3.22 KB
/
julia.qmd
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
---
title: "Julia"
---
[Rembus.jl](https://github.com/cardo-org/Rembus.jl) is the Julia implementation of Rembus specification: it provides a broker implementation and the API for Rembus components.
## Getting Started
Install the `Rembus` package and wait about a minute for downloading and precompilation steps.
```bash
julia> import Pkg; Pkg.add("Rembus")
Resolving package versions...
Installed Rembus ─ v0.2.0
...
Precompiling project...
1 dependency successfully precompiled in 73 seconds. 74 already precompiled.
1 dependency had output during precompilation:
┌ Rembus
│ [2024-05-18T10:36:22.538][Rembus][1][Info] caronte up and running at port tcp:8001
│ [2024-05-18T10:36:23.722][Rembus][1][Info] caronte up and running at port zmq:8002
│ [2024-05-18T10:36:23.951][Rembus][1][Info] caronte up and running at port ws:8000
└
julia>
```
Once the package is installed starts the broker:
```bash
shell> julia -e 'using Rembus; caronte()'
```
The following output shows when `caronte` broker start successfully:
```bash
[2024-05-18T10:41:26.750][Rembus][1][Info] caronte up and running at port ws:8000
```
By default the broker accepts WebSocket connections on port 8000, but plain tcp sockets and ZeroMQ endpoints are possible.
For example start all the protocols with:
```bash
julia -e 'using Rembus; caronte()' -- --ws 8000 --tcp 8001 --zmq 8002
[2024-05-18T10:46:00.063][Rembus][1][Info] caronte up and running at port tcp:8001
[2024-05-18T10:46:00.126][Rembus][1][Info] caronte up and running at port zmq:8002
[2024-05-18T10:46:00.237][Rembus][1][Info] caronte up and running at port ws:8000
```
This finishes the setup, now you are ready to implements your Rembus components.
### Test broker services (RPC)
The `caronte` broker implements itself the `version` and `uptime` RPC services that unsurprisingly returns the broker version and the time in seconds since last reboot.
They may be used to check that `caronte` is up and running:
```julia
using Rembus
@rpc version()
"0.2.0"
@rpc uptime()
"up for 15 seconds"
```
### Implements a service (RPC)
A component that implements a RPC service is just a Julia application that
implements one ore more methods named as the service to be exposed.
The below example define the `stats` service that expects a dataframe as
input and returns some statistics related to the `value` dataframe column.
The returned value is a Dictionary.
```julia
using Statistics
using Rembus
# Return a stat summary of dataframes
# values from the value column.
function stats(df)
return Dict(
"min" => min(df.value...),
"max" => max(df.value...),
"mean" => mean(df.value),
"std" => std(df.value)
)
end
@expose stats
```
The `@expose` macro makes the `stats` method available to connected components.
The following example shows a Julia component that requests the `stats` service and
in the [Python](python.qmd) section there is the equivalent request for a pandas dataframe.
### Request a service (RPC)
A client component that use the `stats` service will just a function call
prefixed with `@rpc`:
```julia
using DataFrames
using Rembus
df = DataFrame(
:name=>["kpi_$i" for i in 1:5],
:ts=>1:5,
:value=>rand(5)
)
summary = @rpc stats(df)
```