4

I want to implement an API rest endpoint with the long polling pattern. The problem with a while loop is, It block the thread so each Http connection take one thread.

For exemple if I have 40 threads available I can only make 40 concurrent Http connection for the long pooling and there are no thread for new requests.

My long pooling request make a call on the database and if there are no result it loop again.

  • I can't use Undertow because it doesn't support OIDC security, I will work on a good pattern in the future but I'm time limited.
  • I saw MySQLPool and Mutiny extension but it doesn't wait for a result with more than 0 row.

Can someone help me ? Thank you :)

There are some code :

In my UserResource

    @GET
    @Path("/lp/by-group/{id}")
    @RolesAllowed({"ADMINISTRATOR"})
    public Multi findByGroupId(@PathParam Long id) {
        return userService.longPoolingByGroupId(id);
    }

In my userService :

    public Multi<UserDTO> longPoolingByGroupId(Long id) {
        return this.userDAO.findAsyncByGroupIdDTO(id);
    }

In my userDAO : findAsyncByGroupIdDTO

return pool.preparedQuery("SELECT * FROM user u LEFT JOIN hos_user_groups ug on u.id = ug.user_id where ug.group_id = " + id)
                .onItem()
                .produceMulti(rows -> Multi.createFrom().items(() -> StreamSupport.stream(rows.spliterator(), false))
                        .onItem().apply(UserDTO::new)

                );
Dorian Maliszewski
  • 821
  • 1
  • 10
  • 14

0 Answers0