Commit e0c61f36 authored by Ali Saeed's avatar Ali Saeed

Added replica for invoicing-service

parent a4e0a45e
......@@ -7,6 +7,7 @@
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="users-service" />
<module name="replica-invoicing-service" />
<module name="invoicing-service" />
<module name="service-discovery" />
<module name="cloud-gateway" />
......@@ -17,6 +18,7 @@
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="cloud-gateway" options="-parameters" />
<module name="invoicing-service" options="-parameters" />
<module name="replica-invoicing-service" options="-parameters" />
<module name="service-discovery" options="-parameters" />
<module name="users-service" options="-parameters" />
</option>
......
......@@ -5,6 +5,8 @@
<file url="file://$PROJECT_DIR$/cloud-gateway/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/invoicing-service/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/invoicing-service/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/replica-invoicing-service/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/replica-invoicing-service/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/service-discovery/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/service-discovery/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
......
......@@ -10,6 +10,10 @@ spring:
uri: lb://invoicing-service
predicates:
- Path=/invoices/**
- id: replica-invoicing-service
uri: lb://invoicing-service
predicates:
- Path=/invoices/**
- id: users-service
uri: lb://users-service
predicates:
......
......@@ -10,6 +10,10 @@ spring:
uri: lb://invoicing-service
predicates:
- Path=/invoices/**
- id: replica-invoicing-service
uri: lb://invoicing-service
predicates:
- Path=/invoices/**
- id: users-service
uri: lb://users-service
predicates:
......
spring.application.name=invoicing-service
server.port=8081
eureka.client.serviceUrl.defaultZone= ${EUREKA_URL:http://localhost:8761/eureka/}
\ No newline at end of file
eureka.client.serviceUrl.defaultZone= ${EUREKA_URL:http://localhost:8761/eureka/}
spring.application.name=invoicing-service
server.port=8081
eureka.client.serviceUrl.defaultZone= ${EUREKA_URL:http://localhost:8761/eureka/}
\ No newline at end of file
eureka.client.serviceUrl.defaultZone= ${EUREKA_URL:http://localhost:8761/eureka/}
......@@ -39,3 +39,47 @@ com.netflix.discovery.shared.transport.TransportException: Cannot execute reques
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at org.springframework.boot.SpringApplicationShutdownHook.run(SpringApplicationShutdownHook.java:108)
at java.base/java.lang.Thread.run(Thread.java:833)
2024-04-27 14:45:09.232 [main] INFO o.e.InvoicingServiceApplication - Starting InvoicingServiceApplication using Java 17 with PID 6092 (D:\Second Semester\Advanced DS\Practical\New folder\micro-services\invoicing-service\target\classes started by dell in D:\Second Semester\Advanced DS\Practical\New folder\micro-services)
2024-04-27 14:45:09.303 [main] DEBUG o.e.InvoicingServiceApplication - Running with Spring Boot v3.0.1, Spring v6.0.3
2024-04-27 14:45:09.306 [main] INFO o.e.InvoicingServiceApplication - No active profile set, falling back to 1 default profile: "default"
2024-04-27 14:45:21.736 [main] INFO o.e.InvoicingServiceApplication - Started InvoicingServiceApplication in 15.264 seconds (process running for 18.594)
2024-04-27 14:52:32.458 [SpringApplicationShutdownHook] ERROR c.netflix.discovery.DiscoveryClient - DiscoveryClient_INVOICING-SERVICE/localhost:invoicing-service:8081 - de-registration failedCannot execute request on any known server
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:112)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.cancel(EurekaHttpClientDecorator.java:71)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$2.execute(EurekaHttpClientDecorator.java:74)
at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.cancel(EurekaHttpClientDecorator.java:71)
at com.netflix.discovery.DiscoveryClient.unregister(DiscoveryClient.java:916)
at com.netflix.discovery.DiscoveryClient.shutdown(DiscoveryClient.java:892)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:424)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeDestroyMethods(InitDestroyAnnotationBeanPostProcessor.java:382)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeDestruction(InitDestroyAnnotationBeanPostProcessor.java:212)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:191)
at org.springframework.beans.factory.support.DisposableBeanAdapter.run(DisposableBeanAdapter.java:184)
at org.springframework.cloud.context.scope.GenericScope$BeanLifecycleWrapper.destroy(GenericScope.java:389)
at org.springframework.cloud.context.scope.GenericScope.destroy(GenericScope.java:136)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:200)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:587)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:559)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:1177)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:520)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:1170)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1082)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1051)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.doClose(ServletWebServerApplicationContext.java:173)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1001)
at org.springframework.boot.SpringApplicationShutdownHook.closeAndWait(SpringApplicationShutdownHook.java:139)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at org.springframework.boot.SpringApplicationShutdownHook.run(SpringApplicationShutdownHook.java:108)
at java.base/java.lang.Thread.run(Thread.java:833)
2024-04-27 14:57:33.199 [main] INFO o.e.InvoicingServiceApplication - Starting InvoicingServiceApplication using Java 17 with PID 4824 (D:\Second Semester\Advanced DS\Practical\New folder\micro-services\invoicing-service\target\classes started by dell in D:\Second Semester\Advanced DS\Practical\New folder\micro-services)
2024-04-27 14:57:33.214 [main] DEBUG o.e.InvoicingServiceApplication - Running with Spring Boot v3.0.1, Spring v6.0.3
2024-04-27 14:57:33.218 [main] INFO o.e.InvoicingServiceApplication - No active profile set, falling back to 1 default profile: "default"
2024-04-27 14:57:49.919 [main] INFO o.e.InvoicingServiceApplication - Started InvoicingServiceApplication in 19.381 seconds (process running for 21.022)
2024-04-27 15:03:12.894 [http-nio-8081-exec-1] INFO o.example.resources.InvoiceResource - Got unpaid invoices for user has 1 userId
2024-04-27 15:05:34.074 [http-nio-8081-exec-3] INFO o.example.resources.InvoiceResource - Got unpaid invoices for user has 1 userId
2024-04-27 14:45:32.428 [main] INFO o.e.ReplicaInvoicingServiceApplication - Starting ReplicaInvoicingServiceApplication using Java 17 with PID 14580 (D:\Second Semester\Advanced DS\Practical\New folder\micro-services\replica-invoicing-service\target\classes started by dell in D:\Second Semester\Advanced DS\Practical\New folder\micro-services)
2024-04-27 14:45:32.440 [main] DEBUG o.e.ReplicaInvoicingServiceApplication - Running with Spring Boot v3.0.1, Spring v6.0.3
2024-04-27 14:45:32.442 [main] INFO o.e.ReplicaInvoicingServiceApplication - No active profile set, falling back to 1 default profile: "default"
2024-04-27 14:45:45.216 [main] INFO o.e.ReplicaInvoicingServiceApplication - Started ReplicaInvoicingServiceApplication in 15.461 seconds (process running for 18.944)
2024-04-27 14:52:32.634 [SpringApplicationShutdownHook] ERROR c.netflix.discovery.DiscoveryClient - DiscoveryClient_INVOICING-SERVICE/localhost:invoicing-service:8082 - de-registration failedCannot execute request on any known server
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:112)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.cancel(EurekaHttpClientDecorator.java:71)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$2.execute(EurekaHttpClientDecorator.java:74)
at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.cancel(EurekaHttpClientDecorator.java:71)
at com.netflix.discovery.DiscoveryClient.unregister(DiscoveryClient.java:916)
at com.netflix.discovery.DiscoveryClient.shutdown(DiscoveryClient.java:892)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:424)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeDestroyMethods(InitDestroyAnnotationBeanPostProcessor.java:382)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeDestruction(InitDestroyAnnotationBeanPostProcessor.java:212)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:191)
at org.springframework.beans.factory.support.DisposableBeanAdapter.run(DisposableBeanAdapter.java:184)
at org.springframework.cloud.context.scope.GenericScope$BeanLifecycleWrapper.destroy(GenericScope.java:389)
at org.springframework.cloud.context.scope.GenericScope.destroy(GenericScope.java:136)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:200)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:587)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:559)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:1177)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:520)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:1170)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1082)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1051)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.doClose(ServletWebServerApplicationContext.java:173)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1001)
at org.springframework.boot.SpringApplicationShutdownHook.closeAndWait(SpringApplicationShutdownHook.java:139)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at org.springframework.boot.SpringApplicationShutdownHook.run(SpringApplicationShutdownHook.java:108)
at java.base/java.lang.Thread.run(Thread.java:833)
2024-04-27 14:58:15.377 [main] INFO o.e.ReplicaInvoicingServiceApplication - Starting ReplicaInvoicingServiceApplication using Java 17 with PID 2868 (D:\Second Semester\Advanced DS\Practical\New folder\micro-services\replica-invoicing-service\target\classes started by dell in D:\Second Semester\Advanced DS\Practical\New folder\micro-services)
2024-04-27 14:58:15.387 [main] DEBUG o.e.ReplicaInvoicingServiceApplication - Running with Spring Boot v3.0.1, Spring v6.0.3
2024-04-27 14:58:15.392 [main] INFO o.e.ReplicaInvoicingServiceApplication - No active profile set, falling back to 1 default profile: "default"
2024-04-27 14:58:28.455 [main] INFO o.e.ReplicaInvoicingServiceApplication - Started ReplicaInvoicingServiceApplication in 16.165 seconds (process running for 18.125)
2024-04-27 15:01:17.962 [http-nio-8082-exec-1] INFO o.example.resources.InvoiceResource - Got unpaid invoices for user has 1 userId
2024-04-27 15:01:59.774 [http-nio-8082-exec-2] INFO o.example.resources.InvoiceResource - Got unpaid invoices for user has 1 userId
2024-04-27 15:04:07.667 [main] INFO o.e.ReplicaInvoicingServiceApplication - Starting ReplicaInvoicingServiceApplication using Java 17 with PID 6272 (D:\Second Semester\Advanced DS\Practical\New folder\micro-services\replica-invoicing-service\target\classes started by dell in D:\Second Semester\Advanced DS\Practical\New folder\micro-services)
2024-04-27 15:04:07.676 [main] DEBUG o.e.ReplicaInvoicingServiceApplication - Running with Spring Boot v3.0.1, Spring v6.0.3
2024-04-27 15:04:07.678 [main] INFO o.e.ReplicaInvoicingServiceApplication - No active profile set, falling back to 1 default profile: "default"
2024-04-27 15:04:18.877 [main] INFO o.e.ReplicaInvoicingServiceApplication - Started ReplicaInvoicingServiceApplication in 13.725 seconds (process running for 15.098)
2024-04-27 15:07:07.363 [http-nio-8082-exec-1] INFO o.example.resources.InvoiceResource - mark the invoice which has 2 invoiceId status as true (paid)
This diff is collapsed.
......@@ -14,6 +14,7 @@
<module>invoicing-service</module>
<module>service-discovery</module>
<module>cloud-gateway</module>
<module>replica-invoicing-service</module>
</modules>
<properties>
......
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>replica-invoicing-service</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-cloud.version>2022.0.0</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.9</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>netflix-candidates</id>
<name>Netflix Candidates</name>
<url>https://artifactory-oss.prod.netflix.net/artifactory/maven-oss-candidates</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</project>
\ No newline at end of file
package org.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication
@EnableDiscoveryClient
public class ReplicaInvoicingServiceApplication {
public static void main(String[] args) {
SpringApplication.run(ReplicaInvoicingServiceApplication.class, args);
}
@Bean
@LoadBalanced
public RestTemplate getRestTemplate(){
return new RestTemplate();
}
}
package org.example.models;
public class Invoice {
private String invoiceID;
private String userID;
private String description;
private boolean status;
private double value;
public Invoice(String invoiceID, String userID, String description, boolean status, double value) {
this.invoiceID = invoiceID;
this.userID = userID;
this.description = description;
this.status = status;
this.value = value;
}
public Invoice() {
this.invoiceID = "";
this.userID = "";
this.description = "description";
this.status = false;
this.value = 0.0;
}
public String getInvoiceID() {
return invoiceID;
}
public void setInvoiceID(String invoiceID) {
this.invoiceID = invoiceID;
}
public String getUserID() {
return userID;
}
public void setUserID(String userID) {
this.userID = userID;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean isStatus() {
return status;
}
public void setStatus(boolean status) {
this.status = status;
}
public double getValue() {
return value;
}
public void setValue(double value) {
this.value = value;
}
@Override
public String toString() {
return "Invoice{" +
"invoiceID='" + invoiceID + '\'' +
", userID='" + userID + '\'' +
", description='" + description + '\'' +
", status=" + status +
", value=" + value +
'}';
}
}
package org.example.models;
public class User {
private String userId;
private String name;
private double balance;
public User(String userId, String name, double balance) {
this.userId = userId;
this.name = name;
this.balance = balance;
}
public User() {
this.userId = "";
this.name = "ali";
this.balance = 0.0;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
@Override
public String toString() {
return "User{" +
"userId='" + userId + '\'' +
", name='" + name + '\'' +
", balance=" + balance +
'}';
}
}
package org.example.resources;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.example.models.Invoice;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
public class ExternalAPI {
public static Invoice getInvoiceDetails(String invoiceId) throws IOException {
String prompt = "{\n" +
" \"prompt\": \"generate just one random json object contains these attributes: value, status, description, userID, invoiceID. where status is false and value is double and invoiceId is " + invoiceId + ", please just return this object without any words else\"\n" +
"}";
String response = sendRequestToAPI(prompt);
String jsonString = "";
int firstIndex = response.toString().indexOf("{");
int endIndex = response.toString().indexOf("}");
jsonString = response.toString().substring(firstIndex, endIndex + 1);
Gson gson = new Gson();
Invoice invoice = gson.fromJson(jsonString, Invoice.class);
System.out.println(invoice.toString());
return invoice;
}
static public List<Invoice> getUnPaidInvoicesForSpecificUser(String userId){
String prompt = "{\n" +
" \"prompt\": \"generate list of random json objects each object contains these attributes: value, status, description, userID, invoiceID. where status is false and value is double and invoiceId is unique and userId is " + userId+ ", please just return this list of objects without any words else\"\n" +
"}";
ArrayList<Invoice> invoices = new ArrayList<Invoice>();
String response = null;
response = sendRequestToAPI(prompt);
String jsonString = "";
int firstIndex = response.toString().indexOf("[");
int endIndex = response.toString().indexOf("]");
jsonString = response.toString().substring(firstIndex, endIndex + 1);
Type listType = new TypeToken<List<Invoice>>() {}.getType();
Gson gson = new Gson();
invoices = gson.fromJson(jsonString, listType);
return invoices;
}
static public List<Invoice> getUnPaidInvoices(){
String prompt = "{\n" +
" \"prompt\": \"generate list of random json objects each object contains these attributes: value, status, description, userID, invoiceID. where status is false and value is double and invoiceId is unique and userId is between 1 to 4, please just return this list of objects without any words else\"\n" +
"}";
ArrayList<Invoice> invoices = new ArrayList<Invoice>();
String response = null;
response = sendRequestToAPI(prompt);
String jsonString = "";
int firstIndex = response.toString().indexOf("[");
int endIndex = response.toString().indexOf("]");
jsonString = response.toString().substring(firstIndex, endIndex + 1);
Type listType = new TypeToken<List<Invoice>>() {}.getType();
Gson gson = new Gson();
invoices = gson.fromJson(jsonString, listType);
return invoices;
}
static public List<Invoice> getPaidInvoices(){
String prompt = "{\n" +
" \"prompt\": \"generate list of random json objects each object contains these attributes: value, status, description, userID, invoiceID. where status is true and value is double and invoiceId is unique and userId is between 1 to 4, please just return this list of objects without any words else\"\n" +
"}";
ArrayList<Invoice> invoices = new ArrayList<Invoice>();
String response = null;
response = sendRequestToAPI(prompt);
String jsonString = "";
int firstIndex = response.toString().indexOf("[");
int endIndex = response.toString().indexOf("]");
jsonString = response.toString().substring(firstIndex, endIndex + 1);
Type listType = new TypeToken<List<Invoice>>() {}.getType();
Gson gson = new Gson();
invoices = gson.fromJson(jsonString, listType);
return invoices;
}
public static String sendRequestToAPI(String prompt) {
RestTemplate restTemplate = new RestTemplate();
String url = "https://fumes-api.onrender.com/llama3";
org.springframework.http.HttpHeaders headers = new org.springframework.http.HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> requestEntity = new HttpEntity<>(prompt, headers);
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
String response = responseEntity.getBody();
System.out.println(response);
return response;
}
}
package org.example.resources;
import org.example.models.Invoice;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping("/invoices")
public class InvoiceResource {
private static final Logger log = LoggerFactory.getLogger(InvoiceResource.class);
@Autowired
RestTemplate restTemplate;
@GetMapping("/getInvoiceDetails/{invoiceId}")
public Invoice getInvoiceDetails(@PathVariable("invoiceId") String invoiceId){
Invoice invoice = null;
try {
invoice = ExternalAPI.getInvoiceDetails(invoiceId);
System.out.println("Got invoice details it's Id is "+ invoiceId);
System.out.println("Got invoice details it's Id is "+ invoiceId);
System.out.println(invoice.toString());
} catch (IOException e){
throw new RuntimeException(e);
}
return invoice;
}
@GetMapping("/getUnPaidInvoicesForSpecificUser/{userId}")
public List<Invoice> getUnPaidInvoicesForSpecificUser(@PathVariable("userId") String userId){
List<Invoice> inv = new ArrayList<>();
inv = ExternalAPI.getUnPaidInvoicesForSpecificUser(userId);
log.info("Got unpaid invoices for user has "+userId+ " userId");
System.out.println("Got unpaid invoices for user has "+userId+ " userId");
return inv;
}
@PostMapping("/updateInvoiceStatus/{invoiceId}")
public boolean updateInvoiceStatus(@PathVariable("invoiceId") String invoiceId){
/* here some logic like get invoice from database and set the status to true */
log.info("mark the invoice which has "+invoiceId+" invoiceId status as true (paid)");
System.out.println("mark the invoice which has "+invoiceId+" invoiceId status as true (paid)");
return true;
}
@GetMapping("/getUnPaidInvoices")
public List<Invoice> getUnPaidInvoices(){
List<Invoice> invoices = new ArrayList<Invoice>();
invoices = ExternalAPI.getUnPaidInvoices();
log.info("Got all unpaid invoices");
System.out.println("Got all unpaid invoices");
return invoices;
}
@GetMapping("/getPaidInvoices")
public List<Invoice> getPaidInvoices(){
List<Invoice> invoices = new ArrayList<Invoice>();
invoices = ExternalAPI.getPaidInvoices();
log.info("Got all paid invoices");
System.out.println("Got all paid invoices");
return invoices;
}
}
spring.application.name=invoicing-service
server.port=8082
eureka.client.serviceUrl.defaultZone= ${EUREKA_URL:http://localhost:8761/eureka/}
<configuration>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>logs/replica-invoicing-service.log</file>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<!-- Console appender -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="org.example" level="DEBUG" additivity="false">
<appender-ref ref="FILE"/>
<appender-ref ref="CONSOLE"/> <!-- Add the console appender reference -->
</logger>
<root level="error">
<appender-ref ref="FILE"/>
<appender-ref ref="CONSOLE"/> <!-- Add the console appender reference -->
</root>
</configuration>
\ No newline at end of file
spring.application.name=invoicing-service
server.port=8082
eureka.client.serviceUrl.defaultZone= ${EUREKA_URL:http://localhost:8761/eureka/}
<configuration>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>logs/replica-invoicing-service.log</file>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<!-- Console appender -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="org.example" level="DEBUG" additivity="false">
<appender-ref ref="FILE"/>
<appender-ref ref="CONSOLE"/> <!-- Add the console appender reference -->
</logger>
<root level="error">
<appender-ref ref="FILE"/>
<appender-ref ref="CONSOLE"/> <!-- Add the console appender reference -->
</root>
</configuration>
\ No newline at end of file
......@@ -11999,3 +11999,15 @@ java.lang.IllegalStateException: Client instance has been closed.
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
2024-04-27 13:39:15.139 [main] INFO o.e.ServiceDiscoveryApplication - Starting ServiceDiscoveryApplication using Java 17 with PID 16984 (D:\Second Semester\Advanced DS\Practical\New folder\micro-services\service-discovery\target\classes started by dell in D:\Second Semester\Advanced DS\Practical\New folder\micro-services)
2024-04-27 13:39:15.222 [main] DEBUG o.e.ServiceDiscoveryApplication - Running with Spring Boot v3.0.1, Spring v6.0.3
2024-04-27 13:39:15.225 [main] INFO o.e.ServiceDiscoveryApplication - No active profile set, falling back to 1 default profile: "default"
2024-04-27 13:39:31.929 [main] INFO o.e.ServiceDiscoveryApplication - Started ServiceDiscoveryApplication in 19.619 seconds (process running for 22.396)
2024-04-27 14:44:29.325 [main] INFO o.e.ServiceDiscoveryApplication - Starting ServiceDiscoveryApplication using Java 17 with PID 8368 (D:\Second Semester\Advanced DS\Practical\New folder\micro-services\service-discovery\target\classes started by dell in D:\Second Semester\Advanced DS\Practical\New folder\micro-services)
2024-04-27 14:44:29.331 [main] DEBUG o.e.ServiceDiscoveryApplication - Running with Spring Boot v3.0.1, Spring v6.0.3
2024-04-27 14:44:29.333 [main] INFO o.e.ServiceDiscoveryApplication - No active profile set, falling back to 1 default profile: "default"
2024-04-27 14:44:44.462 [main] INFO o.e.ServiceDiscoveryApplication - Started ServiceDiscoveryApplication in 17.444 seconds (process running for 19.062)
2024-04-27 14:55:35.265 [main] INFO o.e.ServiceDiscoveryApplication - Starting ServiceDiscoveryApplication using Java 17 with PID 2728 (D:\Second Semester\Advanced DS\Practical\New folder\micro-services\service-discovery\target\classes started by dell in D:\Second Semester\Advanced DS\Practical\New folder\micro-services)
2024-04-27 14:55:35.290 [main] DEBUG o.e.ServiceDiscoveryApplication - Running with Spring Boot v3.0.1, Spring v6.0.3
2024-04-27 14:55:35.292 [main] INFO o.e.ServiceDiscoveryApplication - No active profile set, falling back to 1 default profile: "default"
2024-04-27 14:55:48.675 [main] INFO o.e.ServiceDiscoveryApplication - Started ServiceDiscoveryApplication in 15.859 seconds (process running for 17.358)
......@@ -7,7 +7,6 @@ import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class ServiceDiscoveryApplication {
public static void main(String[] args) {
SpringApplication.run(ServiceDiscoveryApplication.class, args);
}
......
spring.application.name=users-service
server.port=8080
eureka.client.serviceUrl.defaultZone= ${EUREKA_URL:http://localhost:8761/eureka/}
\ No newline at end of file
eureka.client.serviceUrl.defaultZone= ${EUREKA_URL:http://localhost:8761/eureka/}
spring.application.name=users-service
server.port=8080
eureka.client.serviceUrl.defaultZone= ${EUREKA_URL:http://localhost:8761/eureka/}
\ No newline at end of file
eureka.client.serviceUrl.defaultZone= ${EUREKA_URL:http://localhost:8761/eureka/}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment