simple webapp example
2 web apps app a call app-b , in Python port 5000 und 5001
app-a.py
from flask import Flask, render_template_string, request
import requests
import time
import threading
app = Flask(__name__)
app.config['REQUEST_COUNT'] = 0
lock = threading.Lock()
@app.route('/')
def index():
return render_template_string("""
<h1>Welcome to App A</h1>
<form action="/call-b" method="post">
<button type="submit">Call App B</button>
</form>
""")
@app.route('/call-b', methods=['POST'])
def call_b():
with lock:
app.config['REQUEST_COUNT'] += 1
current = app.config['REQUEST_COUNT']
try:
if current % 10 == 0:
print(f"⌛ Simulating 5-second delay on request {current}")
time.sleep(5)
response = requests.get("http://linux:5001/ping")
return f"<h2>Response from App B:</h2><p>{response.text}</p><p>Request #{current}</p>"
except Exception as e:
return f"<h2>Error contacting App B:</h2><pre>{e}</pre><p>Request #{current}</p>"
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
------------
app-b
# app_b.py
from flask import Flask
import instana
app = Flask(__name__)
@app.route('/ping')
def ping():
return "✅ App B reached!"
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5001)
--------