gateway: build: ./gateway ports: - "80:8000"
order-service: build: ./order-service environment: SERVICES_CATALOG_URL: http://catalog-service:8000 RABBITMQ_HOST: rabbitmq ports: - "8003:8000"
try $user = JWTAuth::parseToken()->authenticate(); catch (Exception $e) return response()->json(['error' => 'Unauthorized'], 401); // Inject the user ID from token into the request $request->merge(['authenticated_user_id' => $user->id]);
Run consumer: php artisan queue:work rabbitmq --queue=order.events Instead of exposing three services to the internet, use one Laravel instance as a gateway.
$response = Http::withHeaders([ 'Authorization' => 'Bearer ' . request()->bearerToken() // Pass JWT along ])->get($catalogUrl);
public function handle(OrderPlaced $event) foreach ($event->orderData['items'] as $item) Product::where('id', $item['product_id']) ->decrement('stock', $item['quantity']);
return $next($request); When creating an order, the Order Service must check if the product exists and has stock in the Catalog Service.
Please wait, we will generate a link to the file for you