Skip to content

Commit

Permalink
Merge branch 'main' of ../private
Browse files Browse the repository at this point in the history
  • Loading branch information
lunar-devops committed Aug 20, 2024
2 parents 71ed30f + 7ac1ebb commit efd969c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions example-consumer-app/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class Main {

private static final String URL = "https://catfact.ninja/fact";
private static final long SLEEP_INTERVAL_IN_SEC = 2; // seconds
private static final String X_LUNAR_CONSUMER_TAG = "lunar-example-app";

public static void main(String[] args) {
OkHttpClient client = new OkHttpClient.Builder()
Expand All @@ -21,6 +22,7 @@ public static void main(String[] args) {
while (!Thread.currentThread().isInterrupted()) {
Request request = new Request.Builder()
.url(URL)
.addHeader("x-lunar-consumer-tag", X_LUNAR_CONSUMER_TAG)
.build();

try (Response response = client.newCall(request).execute()) {
Expand Down
8 changes: 7 additions & 1 deletion example-consumer-app/nodejs/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ const readline = require('readline');

const URL = 'https://catfact.ninja/fact';
const SLEEP_INTERVAL_IN_SEC = 2000; // milliseconds
const X_LUNAR_CONSUMER_TAG = 'lunar-example-app';

const getCatFact = () => {
https.get(URL, (res) => {
const options = {
headers: {
'x-lunar-consumer-tag': X_LUNAR_CONSUMER_TAG
}
};
https.get(URL, options, (res) => {
let data = '';

res.on('data', (chunk) => {
Expand Down
7 changes: 5 additions & 2 deletions example-consumer-app/python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@

SLEEP_INTERVAL_IN_SEC = 2
URL = "https://catfact.ninja/fact"

X_LUNAR_CONSUMER_TAG = "lunar-example-app"

async def get_cat_fact(session, stop_event):
while not stop_event.is_set():
try:
async with session.get(URL) as response:
headers = {
"x-lunar-consumer-tag": X_LUNAR_CONSUMER_TAG
}
async with session.get(URL, headers=headers) as response:
if response.status == 200:
fact = (await response.json()).get("fact")
print(f"Cat Fact: {fact}")
Expand Down

0 comments on commit efd969c

Please sign in to comment.