@@ -53,49 +53,8 @@ a Hybrid Connections URL with SAS Tokens utilizing Websockets.
53
53
54
54
1 . Ensure your dependency `config.json` and `relaylib.py` are available in your path
55
55
56
- 2 . Import the dependencies into your `sender.py` script.
57
56
58
- ```python
59
- import asyncio
60
- import json
61
- import logging
62
- import relaylib
63
- import websockets
64
- ```
65
- 3 . Add the following code to the `sender.py` file. The main script should look like the following code:
66
-
67
- ```python
68
- async def run_application(message, config):
69
- service_namespace = config["namespace"]
70
- entity_path = config["path"]
71
- sas_key_name = config["keyrule"]
72
- sas_key = config["key"]
73
- service_namespace += ".servicebus.windows.net"
74
-
75
- # Configure logging
76
- logging.basicConfig(level=logging.DEBUG) # Enable debug logging
77
-
78
- token = relaylib.createSasToken(service_namespace, entity_path, sas_key_name, sas_key)
79
- logging.debug("Token: %s", token)
80
- wss_uri = relaylib.createListenUrl(service_namespace, entity_path, token)
81
- logging.debug("WssURI: %s", wss_uri)
82
-
83
- try:
84
- async with websockets.connect(wss_uri) as websocket:
85
- logging.info("Sending message to Azure Relay WebSocket...")
86
- await websocket.send(json.dumps({"message": message}))
87
- logging.info("Message sent: %s", message)
88
- except Exception as e:
89
- logging.error("An error occurred: %s", str(e))
90
-
91
- if __name__ == "__main__":
92
- # Load configuration from JSON file
93
- with open("config.json") as config_file:
94
- config = json.load(config_file)
95
-
96
- asyncio.run(run_application("This is a message to Azure Relay Hybrid Connections!", config))
97
- ```
98
- Here's what your `sender.py` file should look like:
57
+ 2 . Here's what your `sender.py` file should look like:
99
58
100
59
```python
101
60
import asyncio
0 commit comments