You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The SQS Publisher is a WebAssembly module that generates simulated sensor data and sends it to the SQS Proxy. It can be configured with parameters:
86
94
87
95
-**Interval**: Time between messages (in seconds)
88
-
-**Color**: Hex color code for visual identification
89
-
-**RandomOff**: Whether to use deterministic or random icons
96
+
-**Color**: Hex color code for visual identification or "-1" for random color
97
+
-**Emoji**: Index of emoji to use (-1 for random)
90
98
91
-
It reads its configuration from a YAML file that can be updated while the job is running.
99
+
The configuration is set at startup and remains constant throughout the job's execution.
92
100
93
101
### Message Schema
94
102
95
103
The SQS Publisher sends messages with the following JSON schema:
96
104
97
105
```json
98
106
{
99
-
"job_id": "bacalhau-job-id", // The Bacalhau job ID of the publisher
100
-
"execution_id": "execution-id", // The Bacalhau execution ID
101
-
"icon_name": "🚀", // An emoji representing the message
107
+
"job_id": "bacalhau-job-id", // The Bacalhau job ID of the publisher
108
+
"execution_id": "execution-id", // The Bacalhau execution ID
109
+
"hostname": "edge-node-1", // The hostname of the edge node
110
+
"job_submission_time": 1711449600, // Unix timestamp of when the Bacalhau job was submitted
111
+
"icon_name": "😀", // An emoji from the supported list
102
112
"timestamp": "2025-03-26T12:34:56Z", // ISO 8601 timestamp in UTC
103
-
"color": "#FF5733", // Hex color code from configuration
104
-
"sequence": 42// Sequential message counter
113
+
"color": "#FF5733", // Hex color code
114
+
"sequence": 42, // Sequential message counter
115
+
"region": "us"// Region from environment
105
116
}
106
117
```
107
118
108
119
### Message Fields:
109
120
110
121
-**job_id**: The Bacalhau job ID that identifies the publisher job
111
122
-**execution_id**: The Bacalhau execution ID for the specific execution instance
112
-
-**icon_name**: An emoji selected from a predefined list (random or fixed depending on the `randomOff` configuration)
123
+
-**hostname**: The hostname of the edge node sending the message
124
+
-**job_submission_time**: Unix timestamp of when the Bacalhau job was submitted
125
+
-**icon_name**: An emoji from a predefined list of supported emojis
113
126
-**timestamp**: ISO 8601 formatted timestamp in UTC
114
-
-**color**: Hex color code specified in the configuration
127
+
-**color**: Hex color code (can be specified or random)
115
128
-**sequence**: Incrementing counter for each message sent by this publisher instance
129
+
-**region**: AWS region read from the REGION environment variable
130
+
131
+
### Legacy Implementation
132
+
133
+
The `legacy` directory contains an initial implementation attempt to support updating configuration files at runtime using WebAssembly. This approach was ultimately not pursued due to limitations with the current wazero-based executor. Instead, we now use direct job configuration updates.
116
134
117
-
These messages are sent to the SQS Proxy, which forwards them to Amazon SQS. The SQS Puller then retrieves and processes these messages from the queue.
135
+
The legacy implementation included:
136
+
137
+
-`config-reader`: Attempted to read configuration files at runtime
138
+
-`config-updater`: Attempted to update configuration files at runtime
139
+
-`dir-lister`: Utility for listing directory contents
140
+
-`sqs-publisher`: Previous version of the message publisher
118
141
119
142
### SQS Proxy
120
143
121
144
The SQS Proxy is a FastAPI application that:
145
+
122
146
- Receives HTTP POST requests from edge nodes
123
147
- Forwards valid JSON messages to Amazon SQS
124
148
- Provides a health check endpoint
125
149
- Can be deployed either as a Bacalhau service job or alongside the Docker Compose setup
126
150
127
-
**Important Note**: The SQS Proxy is available at two different ports:
128
-
- Port `8080` when deployed as a Bacalhau service job
129
-
- Port `9090` when deployed via Docker Compose
151
+
**Important Note**: The SQS Proxy URL varies depending on the deployment method:
152
+
153
+
- When deployed via Docker Compose: `http://bacalhau-edge-sqs-proxy-1:9090`
154
+
- When deployed as a Bacalhau service job: `http://bacalhau-edge-web-services-1:8080`
155
+
156
+
Make sure to use the appropriate URL when deploying the SQS Publisher jobs.
130
157
131
158
### SQS Puller
132
159
133
160
The SQS Puller retrieves messages from Amazon SQS and processes them. In this demo, it simply logs messages to stdout but could be extended to:
161
+
134
162
- Process data
135
163
- Trigger alerts
136
164
- Store data in a database
137
165
138
166
Like the SQS Proxy, it can be deployed either as a Bacalhau service job or alongside Docker Compose.
139
167
140
-
### Config Updater
141
-
142
-
The Config Updater is a WASM module that can update the SQS Publisher's configuration file. Due to limitations in Bacalhau v1.7.0, it cannot directly update a running job's configuration. To apply changes:
143
-
144
-
1. Use Config Updater to modify the configuration file
145
-
2. Stop the current SQS Publisher job
146
-
3. Deploy a new SQS Publisher job that will use the updated configuration
147
-
148
168
## 🚀 Getting Started
149
169
150
170
### Prerequisites
@@ -158,6 +178,7 @@ The Config Updater is a WASM module that can update the SQS Publisher's configur
@@ -166,58 +187,131 @@ The Config Updater is a WASM module that can update the SQS Publisher's configur
166
187
2. Create an SQS queue in your AWS account
167
188
168
189
3. Configure your environment:
190
+
169
191
```bash
170
192
cp network/.env.template network/.env
171
193
```
194
+
172
195
Edit `network/.env` and add your AWS credentials and SQS queue URL.
173
196
174
-
4. Start the Bacalhau network:
197
+
### Complete Demo Scenario
198
+
199
+
This scenario demonstrates the message flow and deployment behavior across different regions:
200
+
201
+
1. Start the network:
202
+
203
+
```bash
204
+
./demo.sh start_network
205
+
```
206
+
207
+
2. Deploy to US region with red color and rocket emoji:
208
+
209
+
```bash
210
+
./demo.sh deploy "us""#FF0000" 0
211
+
```
212
+
213
+
This will deploy the SQS Publisher to US edge nodes with red color and rocket emoji 🚀.
214
+
215
+
3. Deploy to EU region with blue color and satellite emoji:
216
+
217
+
```bash
218
+
./demo.sh deploy "eu""#0000FF" 1
219
+
```
220
+
221
+
This will deploy the SQS Publisher to EU edge nodes with blue color and satellite emoji 📡.
222
+
223
+
4. Deploy to AS region with green color and light bulb emoji:
224
+
225
+
```bash
226
+
./demo.sh deploy "as""#00FF00" 2
227
+
```
228
+
229
+
This will deploy the SQS Publisher to AS edge nodes with green color and light bulb emoji 💡.
230
+
231
+
5. Update US deployment with new configuration (purple color and lightning emoji):
232
+
175
233
```bash
176
-
cd network
177
-
docker-compose up -d
234
+
./demo.sh deploy "us""#800080" 3
178
235
```
179
236
237
+
This will deploy a new version of the SQS Publisher to US nodes with purple color and lightning emoji ⚡.
238
+
239
+
6. Disconnect EU region:
240
+
241
+
```bash
242
+
./demo.sh disconnect "eu"
243
+
```
244
+
245
+
This will stop the EU deployment.
246
+
247
+
7. Deploy new configuration to EU (yellow color and battery emoji):
248
+
249
+
```bash
250
+
./demo.sh deploy "eu""#FFFF00" 4
251
+
```
252
+
253
+
This will deploy a new version of the SQS Publisher to EU nodes with yellow color and battery emoji 🔋.
254
+
255
+
8. Reconnect EU region:
256
+
257
+
```bash
258
+
./demo.sh reconnect "eu"
259
+
```
260
+
261
+
This will restart the EU deployment.
262
+
263
+
9. Monitor message flow:
264
+
```bash
265
+
./demo.sh logs
266
+
```
267
+
You should see:
268
+
- Messages from US nodes (new deployment with purple color and lightning emoji ⚡)
269
+
- Messages from EU nodes (new deployment with yellow color and battery emoji 🔋)
270
+
- Messages from AS nodes (green color and light bulb emoji 💡)
271
+
272
+
This demo shows how to deploy and update the SQS Publisher across different regions, with each region having its own unique visual identity through colors and emojis.
273
+
180
274
### Deployment Options
181
275
182
276
#### Option 1: Deploy using Docker Compose Services
183
277
184
278
The provided Docker Compose file already includes the SQS Proxy and SQS Puller services, running on ports:
279
+
185
280
- SQS Proxy: `9090`
186
281
- SQS Puller: logs to Docker Compose logs
187
282
188
283
#### Option 2: Deploy using Bacalhau Service Jobs
189
284
190
285
Deploy the SQS Proxy as a Bacalhau service job:
286
+
191
287
```bash
192
288
bacalhau job run -V queue_url=wasm-sensors-demo jobs/sqs-proxy.yaml
193
289
```
194
290
195
291
Deploy the SQS Puller as a Bacalhau service job:
292
+
196
293
```bash
197
294
bacalhau job run -V queue_url=wasm-sensors-demo jobs/sqs-puller.yaml
198
295
```
199
296
200
297
### Deploy the SQS Publisher to Edge Nodes
201
298
202
299
Deploy the SQS Publisher WebAssembly module targeting the Docker Compose SQS Proxy:
203
-
```bash
204
-
bacalhau job run -V proxy=http://bacalhau-edge-sqs-proxy-1:9090 jobs/sqs-publisher.yaml
205
-
```
206
300
207
-
To target the Bacalhau service job SQS Proxy instead:
208
301
```bash
209
-
bacalhau job run -V proxy=http://bacalhau-edge-web-services-1:8080 jobs/sqs-publisher.yaml
302
+
# With specific color and emoji
303
+
bacalhau job run -V proxy=http://bacalhau-edge-sqs-proxy-1:9090 -V color="#FF5733" -V emoji=0 jobs/sqs-publisher.yaml
304
+
305
+
# With random color and emoji
306
+
bacalhau job run -V proxy=http://bacalhau-edge-sqs-proxy-1:9090 -V color="-1" -V emoji=-1 jobs/sqs-publisher.yaml
210
307
```
211
308
212
-
### Update Configuration
309
+
To target the Bacalhau service job SQS Proxy instead:
213
310
214
-
To update the configuration (note: currently doesn't work with Bacalhau v1.7.0):
215
311
```bash
216
-
bacalhau job run -V color="#FEFEFE"jobs/config-updater.yaml
312
+
bacalhau job run -V proxy=http://bacalhau-edge-web-services-1:8080 -V color="#FF5733" -V emoji=0 jobs/sqs-publisher.yaml
217
313
```
218
314
219
-
As noted earlier, you'll need to restart the SQS Publisher job for these changes to take effect.
-**Configuration Updates**: Due to Bacalhau v1.7.0 limitations, you cannot dynamically update a running job's configuration. You need to stop and redeploy the job.
387
+
-**Configuration Updates**: Configuration is set at job startup and cannot be changed during execution. To change configuration, you need to stop and redeploy the job.
293
388
-**Direct File Access**: WASM modules have limited filesystem access through Bacalhau.
0 commit comments