1

我正在Rest/SSE Api使用创建演示,Quarkus + Panache MongoDb + Reactive但是当使用 cURL 在客户端上连接时,数据被消耗并且连接被关闭。

我期待客户端上的连接会保持打开状态并推送流数据。

class Resource {
    @GET
    @RolesAllowed({"ROLE_ADMIN", "ROLE_COMPANY_READ", "ROLE_COMPANY_SAVE", "COMPANY_DELETE", "ROLE_COMPANY_CREATE"})
    @Produces(MediaType.SERVER_SENT_EVENTS)
    @SseElementType(MediaType.APPLICATION_JSON)
    public Multi<CompanyDto> getAllActiveCompanies(@Context SecurityContext ctx) {
        String name = ctx.getUserPrincipal().getName();
        log.info("hello {}", name);
        Multi<Company> multi = hasRoleAdmin(ctx) ? Company.findActiveCompanies() : Company
            .findActiveCompaniesByUser(name);
        return multi.onItem().apply(c -> companyMapper.toResource(c));
    }

}

客户

curl -H "Authorization: Bearer ..." -v -N http://localhost:8080/api/companies

data: {"activated":true,"createdByUser":"admin@gmail.com","name":"Twitter"}

data: {"activated":true,"createdByUser":"company_admin@gmail.com","name":"My Company"}

data: {"activated":true,"createdByUser":"company_admin@gmail.com","name":"My Company 2"}

* Connection #0 to host localhost left intact

源代码:https ://github.com/rodrigorodrigues/quarkus-rest-api-reactive-mongodb

4

0 回答 0