Julia

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.

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:

shell> julia -e 'using Rembus; caronte()'

The following output shows when caronte broker start successfully:

[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:

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:

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.

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 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:

using DataFrames
using Rembus

df = DataFrame(
  :name=>["kpi_$i" for i in 1:5],
  :ts=>1:5, 
  :value=>rand(5)
)

summary = @rpc stats(df)