Crates.io | ya-service-bus |
lib.rs | ya-service-bus |
version | 0.7.3 |
source | src |
created_at | 2020-09-03 15:16:37.518191 |
updated_at | 2024-04-25 16:10:48.648379 |
description | Golem Service Bus |
homepage | https://github.com/golemfactory/ya-service-bus |
repository | https://github.com/golemfactory/ya-service-bus |
max_upload_size | |
id | 284283 |
size | 177,088 |
GSB is a message bus allowing Yagna services to communicate with one another.
It consist of two software components: router (ya-sb-router
) and client crate
(ya-service-bus
). GSB router is a socket-based message dispatcher. The client
crate provides a high-level API for connecting to the router and allows local
(i.e. within-process, in-memory) routing. GSB supports two distinct ways of
communication: service calls (one-to-one, bidirectional) and broadcasts
(one-to-many, unidirectional).
It is useful for internal development of Golem components or if you want to create your own separated subnet of Golem Network.
YA-SERVICE-BUS - your local repository path
Compile steps:
alternatively you can build from YA-SERVICE-BUS using more complicated command:
Note that ya-sb-router crate can be used as library or binary depending on usage, thus requiring --bin switch to compile correctly
GSB messages are encoded with protobuf. Message types could be found in
gsb_api.proto
file. Each message is prepended with a 64-bit header.
First 4 bytes of the header are interpreted as big-endian singed integer
encoding message type (for mapping see Packet enum).
Next 4 bytes of the header are interpreted as big-endian unsigned integer
representing message length.
Register a service on the bus. Accepts service name as a parameter.
Registered service can be called by its name by other processes connected to GSB.
Service name is treated as a prefix, e.g. a service registered under foo
will
also receive calls to foo/bar
and foo/baz
.
Unregister a service from the bus. No longer receive calls.
Call a service registered on the bus and wait for the reply. Every service call
has an ID, called service's address (name), and call data. Reply from the service
will be returned in one or more CallReply
messages containing call request ID.
Subscribe to a broadcast topic in order to receive all messages published for this topic.
Unsubscribe from a broadcast topic. No longer receive messages.
Broadcast a message to all subscribers of a given topic.
Every 60 seconds router checks for idle connections. If a client has not sent
any message for 60 seconds it is pinged. If a client has not sent any message
for 120 seconds it is disconnected. The timeout is configurable via
GSB_PING_TIMEOUT
environment variable. When a client is disconnected all
registered services and broadcast subscriptions are removed. All pending calls
to a service that got disconnected are answered with ServiceFailure
reply.