-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add forward-to-logger service and requester sample
This commit adds a new service called "forward-to-logger" to the docker-compose.yml file. It also includes a new requester sample that demonstrates how to request data from another service and publish it on a different subject. This allows for forwarding data to the logger service.
- Loading branch information
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Requester Sample | ||
|
||
This sample shows how to request data from another service. | ||
|
||
In a given frequency, the service will request the value from a given subject (with an empty request) and re-publish it on a different subject. | ||
|
||
## Configuration Options | ||
|
||
| Option | Description | Default | | ||
| ------ | ----------- | ------- | | ||
| `REQUEST_SUBJECT` | The subject to request data from. | (required) | | ||
| `PUBLISH_SUBJECT` | The subject to publish the requested data on. | (required) | | ||
| `FREQUENCY` | The frequency to request data from the `REQUEST_SUBJECT` in milliseconds. | `5000` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { startService } from "https://deno.land/x/telestion/mod.ts"; | ||
import { z } from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
||
const { messageBus, config } = await startService(); | ||
|
||
const { FREQUENCY, REQUEST_SUBJECT, OUTPUT_SUBJECT } = z.object({ | ||
FREQUENCY: z.coerce.number().positive().default(5000), | ||
REQUEST_SUBJECT: z.string(), | ||
OUTPUT_SUBJECT: z.string(), | ||
}).parse(config); | ||
|
||
console.log("Request started with config", { | ||
FREQUENCY, | ||
REQUEST_SUBJECT, | ||
OUTPUT_SUBJECT, | ||
}); | ||
|
||
setInterval(async () => { | ||
try { | ||
const data = await messageBus.request(REQUEST_SUBJECT); | ||
console.log("Requester received requested data", data.data); | ||
messageBus.publish(OUTPUT_SUBJECT, data.data); | ||
console.log("Data forwarded to", OUTPUT_SUBJECT); | ||
} catch (e) { | ||
console.warn("Couldn't retrieve data", e); | ||
} | ||
}, FREQUENCY); |