This commit is contained in:
@@ -0,0 +1,34 @@
|
|||||||
|
package com.drinkool.controller;
|
||||||
|
|
||||||
|
import io.smallrye.graphql.client.GraphQLClient;
|
||||||
|
import io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient;
|
||||||
|
import jakarta.ws.rs.POST;
|
||||||
|
import jakarta.ws.rs.Path;
|
||||||
|
import jakarta.ws.rs.core.Response;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
@Path("/api/eatery")
|
||||||
|
public class EateryController {
|
||||||
|
|
||||||
|
@GraphQLClient("eatery")
|
||||||
|
DynamicGraphQLClient dynamicClient;
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("/graphql")
|
||||||
|
public Response forward(String query)
|
||||||
|
throws ExecutionException, InterruptedException {
|
||||||
|
io.smallrye.graphql.client.Response response = dynamicClient.executeSync(
|
||||||
|
query
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.hasError()) {
|
||||||
|
return jakarta.ws.rs.core.Response.status(500)
|
||||||
|
.entity(response.getErrors())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
return jakarta.ws.rs.core.Response.ok(
|
||||||
|
response.getData().toString()
|
||||||
|
).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package com.drinkool.controller;
|
|
||||||
|
|
||||||
import com.drinkool.services.EateryService;
|
|
||||||
import jakarta.inject.Inject;
|
|
||||||
import jakarta.json.JsonObject;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import org.eclipse.microprofile.graphql.GraphQLApi;
|
|
||||||
import org.eclipse.microprofile.graphql.Name;
|
|
||||||
import org.eclipse.microprofile.graphql.Query;
|
|
||||||
|
|
||||||
@GraphQLApi
|
|
||||||
public class GraphQlController {
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
EateryService eateryService;
|
|
||||||
|
|
||||||
@Query("allEateries")
|
|
||||||
public List<JsonObject> getAllEateries() {
|
|
||||||
return eateryService.getAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Query("eateryById")
|
|
||||||
public JsonObject getEatery(@Name("id") UUID id) {
|
|
||||||
return eateryService.getEatery(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package com.drinkool.services;
|
|
||||||
|
|
||||||
import io.smallrye.graphql.client.typesafe.api.GraphQLClientApi;
|
|
||||||
import jakarta.json.JsonObject;
|
|
||||||
import java.util.*;
|
|
||||||
import org.eclipse.microprofile.graphql.Name;
|
|
||||||
|
|
||||||
@GraphQLClientApi(configKey = "eatery")
|
|
||||||
public interface EateryService {
|
|
||||||
public List<JsonObject> getAll();
|
|
||||||
|
|
||||||
public JsonObject getEatery(@Name("id") UUID id);
|
|
||||||
}
|
|
||||||
+10
-10
@@ -13,13 +13,13 @@ spec:
|
|||||||
app: kafdrop
|
app: kafdrop
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: kafdrop
|
- name: kafdrop
|
||||||
image: obsidiandynamics/kafdrop
|
image: obsidiandynamics/kafdrop
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 9000
|
- containerPort: 9000
|
||||||
env:
|
env:
|
||||||
- name: KAFKA_BROKERCONNECT
|
- name: KAFKA_BROKERCONNECT
|
||||||
value: "kafka-service:9092" # Trỏ vào service Kafka của bạn
|
value: "kafka-service:9092"
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Service
|
kind: Service
|
||||||
@@ -30,6 +30,6 @@ spec:
|
|||||||
selector:
|
selector:
|
||||||
app: kafdrop
|
app: kafdrop
|
||||||
ports:
|
ports:
|
||||||
- protocol: TCP
|
- protocol: TCP
|
||||||
port: 9000
|
port: 9000
|
||||||
nodePort: 30900
|
nodePort: 30900
|
||||||
|
|||||||
Reference in New Issue
Block a user