defmodule Dtds do @moduledoc """ This module provides a distributed topic discovery service. Producers and consumers of topics register themselves with the service and can query this information. """ use Application @doc false def start(_type, _args) do Dtds.Supervisor.start_link() end @doc """ Register a consumer for the topic. `term` can be a pid or a registered name. """ def register_consumer(topic, term) do Dtds.TopicRegistry.register(Dtds.TopicRegistry, :consumer, topic, term) end @doc """ Register a producer for the topic. `term` can be a pid or a registered name. """ def register_producer(topic, term) do Dtds.TopicRegistry.register(Dtds.TopicRegistry, :producer, topic, term) end @doc """ Un-register the topic from the consumers. """ def unregister_consumer(topic) do Dtds.TopicRegistry.unregister(Dtds.TopicRegistry, :consumer, topic) end @doc """ Un-register the topic from the producers. """ def unregister_producer(topic) do Dtds.TopicRegistry.unregister(Dtds.TopicRegistry, :producer, topic) end @doc """ Gets the registered name or pid of producer from the node: `node_id` for the `topic` """ def get_producer_for_topic(node_id, topic) do GenServer.call({Dtds.TopicRegistry, node_id}, {:get, :producer, topic}) end @doc """ Gets the registered name or pid of consumer from the node: `node_id` for the `topic` """ def get_consumer_for_topic(node_id, topic) do GenServer.call({Dtds.TopicRegistry, node_id}, {:get, :consumer, topic}) end @doc """ Gets the list of nodes who have the consumers for `topic` """ def get_consumer_nodes(topic) do Dtds.TopicDiscovery.get_consumers_for_topic(Dtds.TopicDiscovery, topic) end @doc """ Gets the list of nodes who have the producers for `topic` """ def get_producer_nodes(topic) do Dtds.TopicDiscovery.get_producers_for_topic(Dtds.TopicDiscovery, topic) end end