mirror of
https://github.com/fluencelabs/registry.git
synced 2025-04-24 17:52:14 +00:00
33 lines
1.1 KiB
Plaintext
33 lines
1.1 KiB
Plaintext
-- This file demonstrates how to send events to subscribers of a topic
|
|
-- Detailed explanation can be found in the Aqua Book: https://doc.fluence.dev/aqua-book/libraries/aqua-dht#passing-data-to-subscribers
|
|
|
|
import "@fluencelabs/registry/routing.aqua"
|
|
import "@fluencelabs/registry/registry.aqua"
|
|
import PeerId from "@fluencelabs/aqua-lib/builtin.aqua"
|
|
|
|
-- Application event
|
|
data Event:
|
|
value: string
|
|
|
|
-- API that every subscriber must adhere to
|
|
-- You can think of it as an application protocol
|
|
service EventAPI:
|
|
receive_event(event: Event)
|
|
|
|
func notify_peer(rec: Record, event: Event):
|
|
-- topological move to peer via relay
|
|
on rec.peer_id via rec.relay_id:
|
|
-- resolve service on a peer
|
|
EventAPI rec.service_id!
|
|
-- call function
|
|
EventAPI.receive_event(event)
|
|
|
|
-- send event to every peer registered on route
|
|
func send_everyone(route_id: string, event: Event, ack: i16):
|
|
on HOST_PEER_ID:
|
|
-- retrieve all peers registered to the route
|
|
records <- resolveRoute(route_id, ack)
|
|
-- iterate through them
|
|
for rec <- records par:
|
|
notify_peer(rec, event)
|