Commit 5eb7d983 authored by Kevin Kaminski's avatar Kevin Kaminski

[AFP-26] Back end can now communicate with front end through...

[AFP-26]  Back end can now communicate with front end through /orders and /orders/{orderId}
parent 3d1389fa
Pipeline #1654 failed with stage
in 77 minutes and 53 seconds
......@@ -12,6 +12,12 @@ To install the Apache Kafka , go to this [link](https://www.apache.org/dyn/close
You then want to unzip the tar file and put it in whatever directory is easiest for you to access.
### Installation Via Homebrew
To install Kafka on your local machine via homebrew, run the following command:
```
brew install kafka
```
## Usage
You want to now open up two separate terminals for running the zookeeper and the kafka server. Once you have two terminals opened up CD into the apache kafka directory in both terminals and run these commands in order:
......@@ -25,7 +31,30 @@ Now in the other terminal you want to run this command
```
bin/kafka-server-start.sh config/server.properties
```
### Usage Via Homebrew Installation
Once Kafka is installed, run the following command to start Kafka Zookeeper:
```
zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties
```
Next, we need to start the Kafka server, use the following command to do so:
```
kafka-server-start /usr/local/etc/kafka/server.properties
```
Once you have both of these commands running you can now go into your IDE of choice or editor, and run the backend java application. Once the application is running you want to send either a curl request with a query param of "message=somethinghere" or use a service like postman and have a query params in there. The route you are going to want to hit is http://localhost:8080/kafka/publish.
Once you have both of these commands running you can now go into your IDE of choice or editor, and run the backend java application. Once the application is running you want to send a POST request - either via curl with a query param of "message=somethinghere" or using a service like postman and have a query params in there. The route you are going to want to hit is http://localhost:8080/kafka/publish.
Example request:
```
http://localhost:8080/kafka/publish?message=somethinghere
```
Once you hit the route mentioned above with the query param, go back to your IDE and you should see producer sending a message and consumer consuming that message.
Example Console Response:
```
2021-05-05 17:13:29.932 INFO 82715 --- [ntainer#0-0-C-1] c.afp.ordermanagement.service.Consumer : #### -> Consumed message -> somethinghere
```
......@@ -18,11 +18,18 @@ public class OrderController {
private OrderService orderService;
@GetMapping("/orders")
@CrossOrigin
public Flux<Order> getAllOrders(){
return orderService.getAllOrders();
}
@GetMapping("/orders/{customerId}")
@GetMapping("/orders/{orderId}")
@CrossOrigin
public Mono<Order> getOrderById(@PathVariable("orderId") String orderId) {
return orderService.getOrderById(orderId);
}
@GetMapping("/orders/byCustomer/{customerId}")
public Flux<Order> getAllOrdersByCustomerId(@PathVariable("customerId") String customerId) {
return orderService.getAllOrdersByCustomerId(customerId);
}
......
......@@ -21,6 +21,10 @@ public class OrderService {
return orderRepository.findAll();
}
public Mono<Order> getOrderById(String orderId) {
return orderRepository.findById(orderId);
}
public Flux<Order> getAllOrdersByCustomerId(String customerId){
return orderRepository.findByCustomerId(customerId);
}
......
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