{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-guides/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["admonition"]},"type":"markdown"},"seo":{"title":"Bus Client Tutorial","description":"Accelerate E&P application development and protect your innovation by consuming our Data and Domain APIs / Platform APIs.","lang":"en-US","meta":[{"name":"robots","content":"noindex"}],"llmstxt":{"hide":true,"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"bus-client-tutorial","__idx":0},"children":["Bus Client Tutorial"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Namespace: ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Agora.Edge"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The BusClient is an integral part of Edge SDK and is implemented as a Singleton.  The purpose of the ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["BusClient"]}," is to send and receive messages using the NATS broker."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/busclient.f824930a3ffb63676ea2572e5bbb2f7d20f1e9694a674d3aa99733f489c9984e.83eefca3.png","alt":"Bus Client"},"children":[]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Configuration Parameters:"]}]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Name (string)"]}," - Used to set the NATS Client Name that identifies the client to the NATS server. Although \"optional\", it is recommended to specify the \"Name\" setting in the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["AEA.json"]}," configuration file. configuration file."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["AEA2:BusClient:Server (string)"]},": Server URL hosting the NATS Server. Default: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["nats://localhost:4222"]},"."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["AEA2:BusClient:Subscriptions (string array)"]},": Array of string topics to subscribe to grouped by their type. Default: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["<empty>"]},".  Commonly, ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["'slbapps.<app-name>.DataIn'"]},", and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["'slbapps.<app-name>.RequestIn'"]}," are frequently used."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["AEA2:BusClient:Targets (string array)"]},": Array of string topics to publish to.  Targets are required to send messages. Default: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["<empty>"]},".  Commonly, ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["'slbapps.<app-name>.DataIn'"]},", and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["'slbapps.<app-name>.RequestIn'"]}," are frequently used."]}]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Prior to SDK 3.0, NATS topics which are now listed in the AEA.json configuration file under Subscriptions and Targets were managed by the AEA broker and enumerated in the routes.json configuration file. With SDK 3.0, the AEA Broker and routes.json are no longer used."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"example-of-aeajson-configuration-file","__idx":1},"children":["Example of ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["AEA.json"]}," configuration file:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"json","header":{"controls":{"copy":{}}},"source":"{\n    \"Name\": \"MyApp\",\n    \"AEA2\": {\n        \"RedisClient\": {\n            \"Server\": \"localhost\",\n            \"Port\": \"6379\"\n        },\n        \"BusClient\": {\n            \"Server\": \"nats://localhost:4222\",\n            \"Subscriptions\": [\n                {\n                    \"DataIn\": [\n                        \"slbapps.MyApp.DataIn\",\n                        \"slbapps.events.DataIn\"\n                    ]\n                },\n                {\n                    \"RequestIn\": [\n                        \"slbapps.MyApp.RequestIn\"\n                    ]\n                },\n                {\n                    \"EventIn\": [\n                        \"slbapps.MyApp.EventIn\"\n                    ]\n                }\n            ],\n            \"Targets\": [\n                {\n                    \"DataOut\": [\n                        \"slbapps.app1.DataIn\",\n                        \"slbapps.app2.DataIn\",\n                    ]\n                },\n                {\n                    \"RequestOut\": [\n                        \"slbapps.app1.RequestIn\",\n                        \"slbapps.app2.RequestIn\",\n                    ]\n                },\n                {\n                    \"EventOut\": [\n                        \"slbapps.app1.EventIn\",\n                        \"slbapps.app2.EventIn\",\n                    ]\n                }\n            ]\n        }\n    }\n}\n","lang":"json"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Properties:"]}]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Instance: BusClient"]}," - Used to access the Singleton instance and is the same as using the Agora.SDK.BusClient."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["IsConnected: bool"]}," -  ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["True"]}," if connected."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Messages: BusMessageQueues"]}," -  Provides access to the queues used to store incoming messages."]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Methods:"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"_","__idx":2},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"#tab/net"},"children":["NET"]}]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["void Connect(int timeout_msec)"]}," - Connects to the Bus using configuration settings."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["bool IsConnected()"]}," - Returns ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["true"]}," if BusClient is connected."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["void SendData(IoDataReportMsg data, string msgTopic = \"DataOut\")"]}," - Sends an IoDataReportMsg to the Bus.  Messages are sent to the topic, ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["msgTopic"]}," which defaults to ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["'DataOut'"]}," list in Targets."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["void SendRequest(RequestMsg request, string msgTopic = \"RequestOut\")"]}," - Sends a RequestMsg to the Bus.  Messages are sent to the topic, ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["msgTopic"]}," which defaults to ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["'RequestOut'"]}," list in Targets."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["void SendMessage(string topic, MessageHeader header, string jsonMessage)"]}," - Sends a json message as json ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["\"payload\""]}," element and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["header"]}," as json ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["\"header\""]}," element using the specified ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["topic"]},"."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["async Task<bool> SendRawMessage(string topic, string message)"]}," - Sends a raw ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["message"]}," as a string to the specified ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["topic"]},"."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["void SendEvent(EventMsg eventmsg, string msgTopic = \"EventOut\")"]}," - Sends a EventMsg to the Bus.  Messages are sent to the topic, ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["msgTopic"]}," which defaults to ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["'EventOut'"]},"  list in Targets."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"_-1","__idx":3},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"#tab/python"},"children":["Python"]}]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["connect(int timeout_sec)"]}," - Connects to the Bus using configuration settings."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["is_connected()"]}," - Returns ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["true"]}," if BusClient is connected."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["send_data(data: IoDataReportMsg, msgTopic = \"DataOut\": str)"]}," - Sends an IoDataReportMsg to the Bus.  Messages are sent to the topic, ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["msgTopic"]}," which defaults to ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["'DataOut'"]}," list in Targets.."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["send_request(request: RequestMsg, msgTopic = \"RequestOut\": str)"]}," - Sends a RequestMsg to the Bus.  Messages are sent to the topic, ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["msgTopic"]}," which defaults to ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["'RequestOut'"]}," list in Targets."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["void send_message(topic: str, header: MessageHeader, jsonMessage: str)"]}," - Sends a json message as json ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["\"payload\""]}," element and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["header"]}," as json ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["\"header\""]}," element using the specified ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["topic"]},"."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["void send_raw_message(topic: str, message: str)"]}," - Sends a raw ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["message"]}," as a string to the specified ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["topic"]},"."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["send_event(event: EventMsg, msgTopic = \"EventOut\": str)"]}," - Sends a EventMsg to the Bus.  Messages are sent to the topic, ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["msgTopic"]}," which defaults to ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["'EventOut'"]}," list in Targets."]}]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]}]},"headings":[{"value":"Bus Client Tutorial","id":"bus-client-tutorial","depth":2},{"value":"Example of AEA.json configuration file:","id":"example-of-aeajson-configuration-file","depth":4},{"value":"","id":"_","depth":1},{"value":"","id":"_-1","depth":1}],"frontmatter":{"seo":{"title":"Bus Client Tutorial"}},"lastModified":"2026-01-14T00:18:30.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/solutions/agora/tutorial/busclienttutorial","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}