https://github.com/lotuc/xnfun
RPC over MQTT (and maybe NOT JUST MQTT)
https://github.com/lotuc/xnfun
edge mqtt rpc rpc-over-mqtt
Last synced: 4 months ago
JSON representation
RPC over MQTT (and maybe NOT JUST MQTT)
- Host: GitHub
- URL: https://github.com/lotuc/xnfun
- Owner: lotuc
- License: other
- Created: 2022-11-22T00:58:09.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T09:12:17.000Z (about 3 years ago)
- Last Synced: 2024-12-29T07:40:56.908Z (over 1 year ago)
- Topics: edge, mqtt, rpc, rpc-over-mqtt
- Language: Clojure
- Homepage:
- Size: 459 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# XNFUN (Cross-Node Functions)
## Documentation
* [Introduction to xnfun](https://lotuc.org/xnfun/intro.html)
* [API Docs](https://lotuc.org/xnfun/lotuc.xnfun.api.html)
## Sample
All the samples assume a running MQTT broker at `tcp://localhost:1883` with no credentials.
- [example1.clj](./src/dev/clj/examples/example1.clj): Unary RPC call
- [example2.clj](./src/dev/clj/examples/example2.clj): Bindirectional RPC call
```clojure
(require '[lotuc.xnfun.api :refer [start-node add-function call]])
;; Start node and register function to node
(def n0 (start-node {:node-options {:hb-interval-ms 3000}}))
(add-function n0 "add" (fn [[a b]] (+ a b)))
(def n1 (start-node {:node-options {:hb-interval-ms 3000}}))
(add-function n1 "sub" (fn [[a b]] (- a b)))
;; Call functions
@(call n0 "add" [4 2])
@(call n0 "sub" [4 2])
@(call n1 "add" [4 2])
@(call n1 "sub" [4 2])
```