Skip to content

Commit

Permalink
Fix Java food ordering example
Browse files Browse the repository at this point in the history
  • Loading branch information
tillrohrmann committed Feb 20, 2025
1 parent 7a73d26 commit 27756a1
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 36 deletions.
58 changes: 37 additions & 21 deletions java/end-to-end-applications/food-ordering/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3'
services:
broker:
image: confluentinc/cp-kafka:7.5.0
Expand All @@ -24,7 +23,7 @@ services:
image: confluentinc/cp-kafka:7.5.0
depends_on:
- broker
entrypoint: [ '/bin/sh', '-c' ]
entrypoint: ["/bin/sh", "-c"]
command: |
"
# blocks until kafka is reachable
Expand All @@ -50,17 +49,29 @@ services:
environment:
- RESTATE_RUNTIME_ENDPOINT=http://runtime:8080
ports:
- "5050:5050" # exposed so that can be called when delivery services run outside docker compose
entrypoint: ["java", "-cp", "@/app/jib-classpath-file", "dev.restate.sdk.examples.RestaurantMain"]
- "5050:5050" # exposed so that can be called when delivery services run outside docker compose
entrypoint:
[
"java",
"-cp",
"@/app/jib-classpath-file",
"dev.restate.sdk.examples.RestaurantMain",
]

driver_app:
container_name: driver_app
image: delivery-service:1.0.0
environment:
- KAFKA_BOOTSTRAP_SERVERS=broker:29092
entrypoint: ["java", "-cp", "@/app/jib-classpath-file", "dev.restate.sdk.examples.external.DriverMobileAppSimulator"]
entrypoint:
[
"java",
"-cp",
"@/app/jib-classpath-file",
"dev.restate.sdk.examples.external.DriverMobileAppSimulator",
]

# To run the delivery services directly (in IDE, standalone), comment out this service
# To run the delivery services directly (in IDE, standalone), comment out this service
delivery_service:
container_name: delivery_service
image: delivery-service:1.0.0
Expand All @@ -80,9 +91,9 @@ services:
- ./restate-docker.toml:/restate.toml:Z,ro
environment:
- RESTATE_CONFIG=/restate.toml
# remove those comments when running delivery services directly (in IDE, standalone), so the runtime can reach out to them
# extra_hosts:
# - "delivery_service:host-gateway"
# remove those comments when running delivery services directly (in IDE, standalone), so the runtime can reach out to them
# extra_hosts:
# - "delivery_service:host-gateway"

runtimesetup:
build:
Expand All @@ -92,19 +103,24 @@ services:
- driver_app
- restaurantpos
restart: "no"
entrypoint: ["sh", "-c", "-x", "sleep 5 &&
echo '-w \"\\n\"' >> ~/.curlrc &&
curl -i -s --fail -X POST 'runtime:9070/deployments' -H 'content-type: application/json' -d '{\"uri\": \"http://delivery_service:9080\"}' &&
curl -i -s --fail -X POST 'runtime:9070/deployments' -H 'content-type: application/json' -d '{\"uri\": \"http://driver_app:9081\"}' &&
sleep 3 &&
curl -i -s --fail -X POST 'runtime:9070/subscriptions' -H 'content-type: application/json' -d '{ \"source\":\"kafka://my-cluster/orders\", \"sink\":\"service://OrderWorkflow/create\" }' &&
curl -i -s --fail -X POST 'runtime:9070/subscriptions' -H 'content-type: application/json' -d '{ \"source\":\"kafka://my-cluster/driver-updates\", \"sink\":\"service://DriverDigitalTwin/handleDriverLocationUpdateEvent\" }' &&
sleep 3 &&
curl -i -s --fail -X POST 'runtime:8080/DriverMobileAppSimulator/driver-A/startDriver' &&
curl -i -s --fail -X POST 'runtime:8080/DriverMobileAppSimulator/driver-B/startDriver' &&
exit 1"]
entrypoint: [
"sh",
"-c",
"-x",
"sleep 5 &&
echo '-w \"\\n\"' >> ~/.curlrc &&
curl -i -s --fail -X POST 'runtime:9070/deployments' -H 'content-type: application/json' -d '{\"uri\": \"http://delivery_service:9080\"}' &&
curl -i -s --fail -X POST 'runtime:9070/deployments' -H 'content-type: application/json' -d '{\"uri\": \"http://driver_app:9081\"}' &&
sleep 3 &&
curl -i -s --fail -X POST 'runtime:9070/subscriptions' -H 'content-type: application/json' -d '{ \"source\":\"kafka://my-cluster/orders\", \"sink\":\"service://OrderWorkflow/create\" }' &&
curl -i -s --fail -X POST 'runtime:9070/subscriptions' -H 'content-type: application/json' -d '{ \"source\":\"kafka://my-cluster/driver-updates\", \"sink\":\"service://DriverDigitalTwin/handleDriverLocationUpdateEvent\" }' &&
sleep 3 &&
curl -i -s --fail -X POST 'runtime:8080/DriverMobileAppSimulator/driver-A/startDriver' &&
curl -i -s --fail -X POST 'runtime:8080/DriverMobileAppSimulator/driver-B/startDriver' &&
exit 1",
]

foodorderingwebui:
webui:
build:
context: ./webui
depends_on:
Expand Down
3 changes: 1 addition & 2 deletions java/end-to-end-applications/food-ordering/webui/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ WORKDIR /app
ENV PATH /node_modules/.bin:$PATH

# install app dependencies
COPY package.json ./
COPY package-lock.json ./
COPY package*.json .
RUN npm install

# add app
Expand Down
4 changes: 2 additions & 2 deletions java/end-to-end-applications/food-ordering/webui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^27.4.1",
"@types/node": "^16.11.25",
"@types/react": "^17.0.43",
"@types/react-dom": "^17.0.14",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@types/styled-components": "^5.1.23",
"@types/uuid": "^8.3.4",
"prettier": "^2.5.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createContext, useContext, FC, useState } from 'react';
import { createContext, useContext, useState } from 'react';
import { ICartDetails, ICartProduct, ICartTotal } from 'models';

export interface ICartContext {
Expand Down Expand Up @@ -40,7 +40,11 @@ const detailsInitialValues = {
checked_out: false,
};

const CartProvider: FC = (props) => {
type Props = {
children?: React.ReactNode;
};

const CartProvider = (props: Props) => {
const [isOpen, setIsOpen] = useState(false);
const [products, setProducts] = useState<ICartProduct[]>([]);
const [total, setTotal] = useState<ICartTotal>(totalInitialValues);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const useCartProducts = () => {
const updateQuantitySafely = (
currentProduct: ICartProduct,
targetProduct: ICartProduct,
quantity: number
quantity: number,
): ICartProduct => {
if (currentProduct.id === targetProduct.id) {
return Object.assign({
Expand All @@ -26,7 +26,7 @@ const useCartProducts = () => {
const addProduct = (newProduct: ICartProduct) => {
let updatedProducts;
const isProductAlreadyInCart = products.some(
(product: ICartProduct) => newProduct.id === product.id
(product: ICartProduct) => newProduct.id === product.id,
);

if (isProductAlreadyInCart) {
Expand All @@ -41,7 +41,7 @@ const useCartProducts = () => {

const removeProduct = (productToRemove: ICartProduct) => {
const updatedProducts = products.filter(
(product: ICartProduct) => product.id !== productToRemove.id
(product: ICartProduct) => product.id !== productToRemove.id,
);

setProducts(updatedProducts);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createContext, useContext, FC, useState } from 'react';
import { createContext, useContext, useState } from 'react';

import { IProduct } from 'models';

Expand All @@ -24,7 +24,11 @@ const useProductsContext = (): IProductsContext => {
return context;
};

const ProductsProvider: FC = (props) => {
type Props = {
children?: React.ReactNode;
};

const ProductsProvider = (props: Props) => {
const [isFetching, setIsFetching] = useState(false);
const [products, setProducts] = useState<IProduct[]>([]);
const [filters, setFilters] = useState<string[]>([]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createContext, useContext, FC, useState } from 'react';
import { createContext, useContext, useState } from 'react';
import { IOrderStatus } from 'models';

export interface IOrderStatusContext {
Expand All @@ -22,7 +22,11 @@ const useOrderStatusContext = (): IOrderStatusContext => {
return context;
};

const OrderStatusProvider: FC = (props) => {
type Props = {
children?: React.ReactNode;
};

const OrderStatusProvider = (props: Props) => {
const [orderStatus, setOrderStatus] = useState<IOrderStatus>({
eta: 0,
status: 'NEW',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createContext, useContext, FC, useState } from 'react';
import { createContext, useContext, useState } from 'react';

import { IUser } from 'models';

Expand All @@ -20,7 +20,11 @@ const useUserContext = (): IUserContext => {
return context;
};

const UserProvider: FC = (props) => {
type Props = {
children?: React.ReactNode;
};

const UserProvider = (props: Props) => {
const [user, setUser] = useState<IUser | undefined>(undefined);
const [isLoadingUser, setLoadingUser] = useState<boolean>(false);

Expand Down

0 comments on commit 27756a1

Please sign in to comment.