microservices: added exception hdlr for PostOrdersAndPayments
This allows the service to continue to try and post orders while the OrdersService is unavailable
or not yet ready.
@@ -138,6 +138,7 @@ public class PostOrdersAndPayments {
// POST order to OrdersService
System.out.printf("Posting order to: %s .... ", path.urlPost());
+ try {
final Response response = client.target(path.urlPost())
.request(APPLICATION_JSON_TYPE)
.post(Entity.json(inputOrder));
@@ -158,9 +159,12 @@ public class PostOrdersAndPayments {
// Send payment
final Payment payment = new Payment("Payment:1234", id(i), "CZK", 1000.00d);
sendPayment(payment.getId(), payment, paymentProducer);
+ i++;
+ } catch (final Exception ex) {
+ System.err.printf("Error communicating with Orders Service, retrying shortly. %s", ex.getMessage());
+ }
Thread.sleep(5000L);
- i++;
}
paymentProducer.flush();
