added fallback defaults for env vars

This commit is contained in:
Steve Waterworth
2018-04-16 15:19:38 +01:00
parent 34880c6219
commit 126f531e96
4 changed files with 14 additions and 7 deletions

View File

@@ -112,7 +112,12 @@ func main() {
LogLevel: instana.Info}))
// Init amqpUri
amqpUri = fmt.Sprintf("amqp://guest:guest@%s:5672/", os.Getenv("AMQP_HOST"))
// get host from environment
amqpHost, ok := os.LookupEnv("AMQP_HOST")
if !ok {
amqpHost = "rabbitmq"
}
amqpUri = fmt.Sprintf("amqp://guest:guest@%s:5672/", amqpHost)
// MQ error channel
rabbitCloseError = make(chan *amqp.Error)

View File

@@ -14,6 +14,9 @@ from rabbitmq import Publisher
app = Flask(__name__)
CART = os.getenv('CART_HOST', 'cart')
USER = os.getenv('USER_HOST', 'user')
@app.route('/health', methods=['GET'])
def health():
return 'OK'
@@ -33,13 +36,13 @@ def pay(id):
queueOrder({ 'orderid': orderid, 'user': id, 'cart': cart })
# add to history
req = requests.post('http://user:8080/order/' + id,
req = requests.post('http://{user}:8080/order/{id}'.format(user=USER, id=id),
data=json.dumps({'orderid': orderid, 'cart': cart}),
headers={'Content-Type': 'application/json'})
app.logger.info('order history returned {}'.format(req.status_code))
# delete cart
req = requests.delete('http://cart:8080/cart/' + id);
req = requests.delete('http://{cart}:8080/cart/{id}'.format(cart=CART, id=id));
app.logger.info('cart delete returned {}'.format(req.status_code))
return jsonify({ 'orderid': orderid })

View File

@@ -3,7 +3,7 @@ import pika
import os
class Publisher:
HOST = os.getenv("AMQP_HOST", "rabbitmq")
HOST = os.getenv('AMQP_HOST', 'rabbitmq')
VIRTUAL_HOST = '/'
EXCHANGE='robot-shop'
TYPE='direct'

View File

@@ -37,9 +37,8 @@ public class Main {
public static void main(String[] args) {
// Get ENV configuration values
Map<String, String> env = System.getenv();
CART_URL = String.format("http://%s/shipping/", env.get("CART_ENDPOINT"));
JDBC_URL = String.format("jdbc:mysql://%s/cities?useSSL=false&autoReconnect=true", env.get("DB_HOST"));
CART_URL = String.format("http://%s/shipping/", System.getenv("CART_ENDPOINT") != null ? System.getenv("CART_ENDPOINT") : "cart");
JDBC_URL = String.format("jdbc:mysql://%s/cities?useSSL=false&autoReconnect=true", System.getenv("DB_HOST") != null ? System.getenv("DB_HOST") : "mysql");
//
// Create database connector