-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from nawaphonOHM/messaging/graphql
Messaging/graphql
- Loading branch information
Showing
20 changed files
with
365 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
services: | ||
|
||
gateway: | ||
image: nawaphon2539/microservices-lab:messaging.graphql.gateway | ||
env_file: | ||
- gateway/gateway-vars.env | ||
ports: | ||
- "1001:8080" | ||
networks: | ||
default: | ||
ipv4_address: 192.168.1.2 | ||
|
||
|
||
networks: | ||
default: | ||
ipam: | ||
config: | ||
- subnet: 192.168.1.0/29 | ||
gateway: 192.168.1.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
FROM openjdk:11.0.16-jre | ||
|
||
|
||
RUN useradd --create-home gateway | ||
|
||
COPY ./build/libs/gateway-0.0.1.jar /home/gateway/ | ||
COPY ./entrypoint.sh /home/gateway/ | ||
|
||
RUN chown gateway /home/gateway/entrypoint.sh && \ | ||
chmod 500 /home/gateway/entrypoint.sh && \ | ||
chown gateway /home/gateway/gateway-0.0.1.jar && \ | ||
chmod 500 /home/gateway/gateway-0.0.1.jar | ||
|
||
|
||
EXPOSE 8080 | ||
|
||
USER gateway | ||
|
||
WORKDIR /home/gateway/ | ||
|
||
ENTRYPOINT ["./entrypoint.sh"] | ||
|
||
LABEL authors="nawaphon" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
group = 'nawaphon.microservices.gateway' | ||
version = '0.0.1' | ||
|
||
|
||
archivesBaseName = 'gateway' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
|
||
main() { | ||
|
||
export ERROR=0 | ||
|
||
mandatoryEnvCheck | ||
|
||
if [ "$ERROR" -eq 1 ]; then | ||
exit 1 | ||
fi | ||
|
||
unset ERROR | ||
|
||
java -jar /home/gateway/gateway-0.0.1.jar || exit 1 | ||
} | ||
|
||
mandatoryEnvCheck() { | ||
ERROR=0 | ||
} | ||
|
||
|
||
|
||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
TZ=Asia/Bangkok | ||
LOG_LEVEL=DEBUG |
13 changes: 13 additions & 0 deletions
13
...teway/src/main/java/nawaphon/microservices/event_sourcing/gateway/GatewayApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package nawaphon.microservices.event_sourcing.gateway; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class GatewayApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(GatewayApplication.class, args); | ||
} | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
.../java/nawaphon/microservices/event_sourcing/gateway/components/FakeDatabaseComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package nawaphon.microservices.event_sourcing.gateway.components; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import nawaphon.microservices.event_sourcing.gateway.pojo.Customer; | ||
import nawaphon.microservices.event_sourcing.gateway.pojo.CustomerDetail; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.annotation.PostConstruct; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
@Component | ||
public class FakeDatabaseComponent { | ||
private static final Logger logger = LogManager.getLogger(FakeDatabaseComponent.class); | ||
|
||
private final List<Customer> customers = new ArrayList<>(); | ||
private final List<CustomerDetail> customerDetails = new ArrayList<>(); | ||
|
||
private final ObjectMapper objectMapper; | ||
|
||
public FakeDatabaseComponent(final ObjectMapper objectMapper) { | ||
this.objectMapper = objectMapper; | ||
} | ||
|
||
public List<Customer> getCustomers() { | ||
return customers; | ||
} | ||
|
||
public List<CustomerDetail> getCustomerDetails() { | ||
return customerDetails; | ||
} | ||
|
||
@PostConstruct | ||
public void makeData() { | ||
Customer customerFake; | ||
CustomerDetail customerDetailFake; | ||
|
||
{ | ||
customerFake = new Customer(UUID.randomUUID(), UUID.randomUUID()); | ||
customerDetailFake = new CustomerDetail(customerFake.getDetailsId(), "John", "Doe"); | ||
customers.add(customerFake); | ||
customerDetails.add(customerDetailFake); | ||
try { | ||
logger.info("Customer and CustomerDetail added: {}", objectMapper.writeValueAsString(customerFake)); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException("Unable to serialize value: ", e); | ||
} | ||
} | ||
|
||
{ | ||
customerFake = new Customer(UUID.randomUUID(), UUID.randomUUID()); | ||
customerDetailFake = new CustomerDetail(customerFake.getDetailsId(), "Jane", "Smith"); | ||
customers.add(customerFake); | ||
customerDetails.add(customerDetailFake); | ||
try { | ||
logger.info("Customer and CustomerDetail added: {}", objectMapper.writeValueAsString(customerFake)); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException("Unable to serialize value: ", e); | ||
} | ||
} | ||
|
||
{ | ||
customerFake = new Customer(UUID.randomUUID(), UUID.randomUUID()); | ||
customerDetailFake = new CustomerDetail(customerFake.getDetailsId(), "Bob", "Johnson"); | ||
customers.add(customerFake); | ||
customerDetails.add(customerDetailFake); | ||
try { | ||
logger.info("Customer and CustomerDetail added: {}", objectMapper.writeValueAsString(customerFake)); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException("Unable to serialize value:", e); | ||
} | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...c/main/java/nawaphon/microservices/event_sourcing/gateway/controllers/MainController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package nawaphon.microservices.event_sourcing.gateway.controllers; | ||
|
||
import nawaphon.microservices.event_sourcing.gateway.components.FakeDatabaseComponent; | ||
import nawaphon.microservices.event_sourcing.gateway.pojo.Customer; | ||
import nawaphon.microservices.event_sourcing.gateway.pojo.CustomerDetail; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.graphql.data.method.annotation.Argument; | ||
import org.springframework.graphql.data.method.annotation.QueryMapping; | ||
import org.springframework.graphql.data.method.annotation.SchemaMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.UUID; | ||
|
||
@RestController | ||
public class MainController { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(MainController.class); | ||
|
||
private final FakeDatabaseComponent fakeDatabaseComponent; | ||
|
||
public MainController(final FakeDatabaseComponent fakeDatabaseComponent) { | ||
this.fakeDatabaseComponent = fakeDatabaseComponent; | ||
} | ||
|
||
@QueryMapping("findCustomerById") | ||
public Customer getCustomer(@Argument final UUID id) { | ||
logger.info("Getting customer with id: {}", id); | ||
return fakeDatabaseComponent.getCustomers().stream().filter((var1) -> var1.getId().compareTo(id) == 0) | ||
.findFirst().orElse(new Customer()); | ||
} | ||
|
||
@SchemaMapping("details") | ||
public CustomerDetail getCustomerDetails(final Customer customer) { | ||
logger.info("Getting customer details for customer with id: {}", customer.getId()); | ||
return fakeDatabaseComponent.getCustomerDetails().stream() | ||
.filter((var1) -> var1.getCustomerId().compareTo(customer.getDetailsId()) == 0) | ||
.findFirst().orElse(new CustomerDetail()); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...ql/gateway/src/main/java/nawaphon/microservices/event_sourcing/gateway/pojo/Customer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package nawaphon.microservices.event_sourcing.gateway.pojo; | ||
|
||
import java.util.UUID; | ||
|
||
public class Customer { | ||
|
||
private final UUID id; | ||
|
||
private final UUID detailsId; | ||
|
||
|
||
public Customer(final UUID id, final UUID detailsId) { | ||
this.id = id; | ||
this.detailsId = detailsId; | ||
} | ||
|
||
public Customer() { | ||
this(null, null); | ||
} | ||
|
||
public UUID getId() { | ||
return id; | ||
} | ||
|
||
public UUID getDetailsId() { | ||
return detailsId; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...eway/src/main/java/nawaphon/microservices/event_sourcing/gateway/pojo/CustomerDetail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package nawaphon.microservices.event_sourcing.gateway.pojo; | ||
|
||
import java.util.UUID; | ||
|
||
public class CustomerDetail { | ||
|
||
private final UUID customerId; | ||
|
||
private final String firstName; | ||
|
||
private final String lastName; | ||
|
||
|
||
public CustomerDetail(final UUID customerId, final String firstName, final String lastName) { | ||
this.customerId = customerId; | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
} | ||
|
||
public CustomerDetail() { | ||
this(null, null, null); | ||
} | ||
|
||
public UUID getCustomerId() { | ||
return customerId; | ||
} | ||
|
||
public String getFirstName() { | ||
return firstName; | ||
} | ||
|
||
public String getLastName() { | ||
return lastName; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...way/src/main/java/nawaphon/microservices/event_sourcing/gateway/pojo/ResponseMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package nawaphon.microservices.event_sourcing.gateway.pojo; | ||
|
||
public class ResponseMessage<A> { | ||
|
||
private final Number code; | ||
private final String message; | ||
private final A results; | ||
|
||
public ResponseMessage(final Number code, final String message, final A results) { | ||
this.code = code; | ||
this.message = message; | ||
this.results = results; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public A getResults() { | ||
return results; | ||
} | ||
|
||
public Number getCode() { | ||
return code; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
messaging/graphql/gateway/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
server.servlet.context-path=/gateway | ||
logging.level.root=${LOG_LEVEL:INFO} | ||
|
||
spring.graphql.graphiql.enabled=true | ||
|
||
|
4 changes: 4 additions & 0 deletions
4
messaging/graphql/gateway/src/main/resources/graphql/Customer.graphqls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
type Customer { | ||
id: ID | ||
details: CustomerDetail | ||
} |
5 changes: 5 additions & 0 deletions
5
messaging/graphql/gateway/src/main/resources/graphql/CustomerDetail.graphqls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
type CustomerDetail { | ||
customerId: ID | ||
firstName: String | ||
lastName: String | ||
} |
3 changes: 3 additions & 0 deletions
3
messaging/graphql/gateway/src/main/resources/graphql/graphql.config.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
schema: | ||
- ./*.graphqls | ||
documents: '**/*.graphql' |
5 changes: 5 additions & 0 deletions
5
messaging/graphql/gateway/src/main/resources/graphql/schema.graphqls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
type Query { | ||
findCustomerById(id: ID): Customer | ||
|
||
} | ||
|
13 changes: 13 additions & 0 deletions
13
...n/microservices/event_sourcing/consumer/EventSourcingServiceConsumerApplicationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package nawaphon.microservices.event_sourcing.consumer; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@SpringBootTest | ||
class EventSourcingServiceConsumerApplicationTests { | ||
|
||
@Test | ||
void contextLoads() { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters