astarte-platform / astarte-message-hub Goto Github PK
View Code? Open in Web Editor NEWLicense: Apache License 2.0
License: Apache License 2.0
After this PR is merged #202
The publisher and subscriber are passed in the AstarteHandle
, this will not make it possible to restart the MessageHub if the thread that handles the MQTT event loop crashes.
Currently all node interfaces have been received during the attach
procedure without being cached or persisted, so the message-hub should internally keep all interfaces until the detach method is called by the node..
This can improve in case of astarte-message restart, it already having the introspection will be able to receive the message from an Astarte instance without waiting for the interfaces to be sent froms nodes.
The main.rs
function does not yet contain anything except the initialization of the MessageHubOptions
.
The initialization of the AstarteMessageHub
should be added together with a runner for the MessageHubServer
.
The astarte handler is missing a new()
function. It furthermore only exposes as public the device_sdk
field.
No worflow/job is present in the CI to perform linting using clippy
.
Add to the message-hub config file the configuration of number of seconds after which client should ping the broker if there is no other data exchange.
Add to MessageHubOptions struct:
astarte-message-hub/src/config/mod.rs
Line 52 in e673860
Pass to Astarte Device SDK Options: https://github.com/astarte-platform/astarte-message-hub/blob/e673860701ca42a2e663d9c1be279669b1b872fc/src/main.rs#L93C31-L93C45
Possible names:
mqtt_keep_alive
mqtt_connection_keep_alive
...
Most of the sources are lacking docstrings.
It would be useful to add short comments for each function/struct.
Add something like this https://github.com/edgehog-device-manager/edgehog-device-runtime#configuration
The Astarte message hub will eventually run a protobuf server (once #75 is completed).
However, there is no way of setting a specific port to use when communicating with the protobuf server.
It should be evaluated if a dynamic configuration of the message hub protobuf server port is required.
Some files, modules, and functions could be renamed to have clearer names.
For example:
Astarte
could be renamed to AstarteHandler
astarte_provider.rs
could be renamed to astarte_handler.rs
mock_astarte.rs
could be renamed to mock_astarte_sdk.rs
Metadata is a side channel that allows clients and servers to provide information to each other that is associated with an RPC.
gRPC metadata is a key-value pair of data that is sent with initial or final gRPC requests or responses. It is used to provide additional information about the call, such as authentication credentials, tracing information, or custom headers.
Try to figure out if it is possible to move the node id from the Attach
message to the GRPC metadata.
It would be nice to have an Astarte interface that collects statistics from the nodes attached to the Message Hub.
An interface name would be : org.astarte-paltform.messagehub.NodeStats
Mapping:
/$node_id/$interface_name/messages
Currently AstarteMessage can only send/receive AstarteData, so it is better to add a layer on top of AstarteMessage giving the possibility to add other fields in AstarteDataMessage, without introduce a breaking changes in the API.
Other fields can be:
an error during the send or receive data.
an event from Astarte for a specific node ( for instance , an interface with higher major was added in the introscpection)
etc.
Rename astarte_message.proto
to astarte_data_message.proto
.
Add AstarteDataMessge.
message AstarteDataMessage{
AstarteMessage astarte_message = 1;
AstarteFailure/AstarteError? = 2;
...
}
The Astarte handler run
function is not called within the AstarteMessageHub
.
I propose two different approaches:
run
function for the AstarteMessageHub
, containing a call to the run
function of the Astarte handler. This function however would need to be called in a separate thread due to its blocking nature. This would require the clone
trait to be implemented for the AstarteMessageHub
struct.AstarteMessageHub
in which to call the run
function.When the configuration of Astarte-message-hub was provided via HTTP or GRPC-PROTOBUF APIs , the toml file generated by MessageHubOptions
must be saved in a writable path, because the default path configured in /etc
or the local path of message-hub may not be writable, so it should be saved in the store_directory
provided by the MessageHubOptions
.
This will let us share the protobuf definitions as a git submodule between the rust and python SDK
If a node goes offline without calling the detach method, all messages directed to it should be stored and on return sent back to the node.
sequenceDiagram
Node-A->>+MessageHub: Attach
Node-A->>+Node-A: go offline
Astarte->>+MessageHub: Send data
alt check Node-A is online
MessageHub->>MessageHub: Store message for Node-A
end
Node-A-->>-Node-A: back online
Node-A->>+MessageHub: Attach
MessageHub->>+Node-A: Send data
The result failed of calls handle_events
is not logged in main run
function.
astarte-message-hub/src/data/astarte_handler.rs
Lines 193 to 197 in e880fd6
Currently a messageHub node can add the astarte interfaces only calling the Attach
method, it should be better add a separated method.
Currently the message hub allows to send a message from node even if it is not attached to the message hub, this should be avoided.
Solution: Check node-id before send the message.
Directory used by Astarte-Message-Hub to retain persistent data
Make it configurable, the Astarte Message Hub should be support different configuration ways ( config.toml, API Rest, proto method etc )
Configuration files licensing headers refer to Edgehog instead of Astarte.
The files are file.rs
, http.rs
, protobuf.rs
, mod.rs
.
astarte-message-hub/src/config/mod.rs
Line 2 in b870447
Specifying the methods that can be called with their parameters and return types.
Split the package into multiple library crates to separate astarte-message-hub-types from the astarte-message-hub application allowing separate distribution of the astarte-message-hub-types crate.
Cargo offers a feature called workspaces that can help manage multiple related packages that are developed in tandem.
A workspace is a set of packages that share the same Cargo.lock and output directory.
Cargo-Workspace
Write simple library to wrap Astarte SDK, use something like trait Publisher that we are using in Edgehog Device Runtime.
Example of Astarte traits for wrapping Astarte SDK Device
#[async_trait]
pub trait AstartePublisher: Send + Sync {
async fn send_object<T: 'static>(
&self,
interface_name: &str,
interface_path: &str,
data: T,
) -> Result<(), AstarteError>
where
T: serde::Serialize + Send;
async fn send(
&self,
interface_name: &str,
interface_path: &str,
data: AstarteType,
) -> Result<(), AstarteError>;
}
#[async_trait]
pub trait AstarteSubscriber {
async fn subscribe(
&self,
astarte_node: &AstarteNode,
) -> Result<Receiver<Result<AstarteMessage, Status>>, AstarteError>;
async fn unsubscribe(&self, astarte_node: AstarteNode) -> Result<(), AstarteError>;
}
Currently the Astarte message hub doesn't support an ack mechanism to signal the exact receipt of a message by a node.
For add the ack support the message-hub needs:
ack_message(message_id)
to send the ack signal from the node to Astarte message hub.Add an option in the config to be able to use the SQLite store with the Astarte SDK.
The database would be store in the already present store_directory, we should add a boolean option to the MessageHubOptions
to enable the SQLite store.
It would be nice to have an Astarte interface that collects information about the nodes attached to the Message Hub.
An interface name would be : org.astarte-paltform.messagehub.NodeInfo
Mapping:
node_id
attached to the Message Hub, maybe a settable/unsettable boolean property like /${node_id}/attached
.interfaces
of each node, it would be a settable/unsettable strings array like /${node_id}/interfaces
If no credential secret is present, the Astarte message hub register a new device, this operation return a credentials secret should be preserved even after restart or reboot.
astarte-message-hub/src/main.rs
Line 42 in 59d4b0a
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.