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
1
class TicketController
2
{
3
private QueryBus $queryBus;
4
5
public function __construct(QueryBus $queryBus)
6
{
7
$this->queryBus = $queryBus;
8
}
9
10
public function getTicketStatusAction(Request $request) : Response
11
{
12
return new Response(
13
$this->queryBus->sendWithMetadata(
14
new GetTicketStatusQuery($request->get("ticketId")),
15
expectedReturnedMediaType: "application/json"
16
);
17
)
18
}
19
}
Copied!
1
$queryBus = $messagingSystem->getQueryBus();
2
3
// result will be in json
4
$result = $queryBus->sendWithMetadata(
5
new GetTicketStatusQuery($ticketId),
6
expectedReturnedMediaType: "application/json"
7
);
Copied!
Handler
1
class GetTicketStatusQueryHandler
2
{
3
#[QueryHandler]
4
public function getTicketStatus(GetTicketStatusQuery $query)
5
{
6
return ["ticketId" => $query->getTicketId(), "status" => "inProgress"];
7
}
8
}
Copied!
Export as PDF
Copy link