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
Copy file name to clipboardExpand all lines: README.md
+9-2Lines changed: 9 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -145,8 +145,8 @@ async function handleDataAggregation(sensorUID): Promise<void> {
145
145
}
146
146
```
147
147
148
-
Please note that in a real-world scenario, sensor UIDs are more likely to be consumed from a message queue (e.g., RabbitMQ, Kafka, AWS SNS) rather than from an in-memory array. This setup **highlights the benefits** of avoiding backpressure:
149
-
We should avoid consuming a message if we cannot start processing it immediately. Working with message queues typically involves acknowledgements, which have timeout mechanisms. Therefore, immediate processing is crucial to ensure efficient and reliable handling of messages.
148
+
Please note that in a real-world scenario, sensor UIDs may be consumed from a message queue (e.g., RabbitMQ, Kafka, AWS SNS) rather than from an in-memory array. This setup **highlights the benefits** of avoiding backpressure:
149
+
We should avoid consuming a message if we cannot start processing it immediately. Working with message queues typically involves acknowledgements, which have **timeout** mechanisms. Therefore, immediate processing is crucial to ensure efficient and reliable handling of messages. The `waitForAvailability` method addresses this need by checking availability as a preliminary action before consuming a message.
150
150
Refer to the following adaptation of the previous example, where sensor UIDs are consumed from a message queue. This example overlooks error handling and message validation, for simplicity.
151
151
152
152
```ts
@@ -165,6 +165,7 @@ async function processConsumedMessages(): Promise<void> {
@@ -173,6 +174,9 @@ async function processConsumedMessages(): Promise<void> {
173
174
174
175
++numberOfProcessedMessages;
175
176
const { uid } =message.data;
177
+
178
+
// At this point, `startExecution` will begin immediately, due to the
179
+
// preliminary `waitForAvailability` action.
176
180
awaitsensorAggregationSemaphore.startExecution(
177
181
():Promise<void> =>handleDataAggregation(uid);
178
182
);
@@ -200,6 +204,9 @@ async function processConsumedMessages(): Promise<void> {
200
204
}
201
205
```
202
206
207
+
In reference to the above example, please note that `waitForAvailability` may be considered overkill or redundant if the job's duration is significantly shorter than the message timeout.
208
+
For example, if the message queue's timeout for acknowledging a message is 1 minute and a typical job duration is 1 second, the 59 second gap provides a substantial safety margin. In such cases, the preliminary `waitForAvailability` action can be omitted.
209
+
203
210
## 2nd use-case: Single Job Execution
204
211
205
212
The `waitForCompletion` method is useful for executing a sub-procedure, for which the caller must wait before proceeding with its work.
0 commit comments