Converting Query Handler Result

Query Result PHP

If you have registered Converter for specific Media Type, then you can tell Ecotone to convert result of any Gateway to specific format. This is especially useful, when we are dealing with QueryBus, when we want to return the result to the caller of the request. In order to do this, we need to make use of Metadataand replyContentType header.

Symfony / Laravel
Lite
Symfony / Laravel
class TicketController
{
private QueryBus $queryBus;
public function __construct(QueryBus $queryBus)
{
$this->queryBus = $queryBus;
}
public function getTicketStatusAction(Request $request) : Response
{
return new Response(
$this->queryBus->sendWithMetadata(
new GetTicketStatusQuery($request->get("ticketId")),
["replyContentType" => "application/json"]
);
)
}
}
Lite
$queryBus = $messagingSystem->getGatewayByName(QueryBus::class);
// result will be in json
$result = $queryBus->sendWithMetadata(
new GetTicketStatusQuery($ticketId),
["replyContentType" => "application/json"]
);
Handler
Handler
class GetTicketStatusQueryHandler
{
#[QueryHandler]
public function getTicketStatus(GetTicketStatusQuery $query)
{
return ["ticketId" => $query->getTicketId(), "status" => "inProgress"];
}
}