Last active
July 12, 2023 15:34
-
-
Save dgafka/2cd6ea262079852f63b366a14f6bb095 to your computer and use it in GitHub Desktop.
microservices-integration-in-php-04.php
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
<?php | |
class OrderService | |
{ | |
public function __construct(private DistributedBus $distributedBus) {} | |
public function placeOrder(int $personId, array $products): void | |
{ | |
$this->distributedBus->sendCommand( | |
"order_service", // 1. External Service Name | |
"placeOrder", // 2. Routing in external Service | |
\json_encode(["personId" => $personId, "products" => $products]), // 3. Our payload | |
"application/json" // 4. Content-Type of payload | |
); | |
} | |
} | |
// with Converters we could let Ecotone to do the conversion. | |
public function placeOrder(int $personId, array $products): void | |
{ | |
$this->distributedBus->convertAndSendCommand( | |
"order_service", // 1. External Service Name | |
"placeOrder", // 2. Routing in external Service | |
new PlaceOrder($personId, $products) // 3. Our payload | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment