These are chat archives for spring-cloud/spring-cloud

2nd
Mar 2019
Bruce Zhang
@niyaode
Mar 02 09:02

I'm asking a question on stackoverflow, help me with it.

In a microservice environment, spring-data-jpa paging queries cannot backfill the query data

Paging query on the client server requests resources server, server resources query results and return org.springframework.data.domain.Page interface.I can't use it on the client server.I encapsulated it as an entity object but the problem was that the parameters of the conditional query could not be passed.

Resource Server

@Override
    public Page<RoleEntity> findAllPage(int page, int pageSize) {
ExampleMatcher.GenericPropertyMatchers.startsWith());
        return roleDao.findAll(PageRequest.of(page-1, pageSize,Sort.by(Sort.Order.desc("id"))));
    }

Client server pagination

<nav aria-label="..." th:fragment="simplePage(jpaPageTool)">
    <ul class="pagination">
        <li class="page-item" th:classappend="${jpaPageTool.isFirstPage}?'disabled':''">
            <a class="page-link" th:href="@{${#request.getRequestURI()}(page=${jpaPageTool.page-1})}" aria-label="Previous">
                <span aria-hidden="true">&laquo;</span>
                <span class="sr-only">Previous</span>
            </a>
        </li>
        <div th:text="${#request.getQueryString()}"></div>

        <th:block th:if="${jpaPageTool.totalPages < 10}">
            <th:block th:each="pageNo : ${#numbers.sequence(1, jpaPageTool.totalPages)}">
            <li class="page-item " th:classappend="${jpaPageTool.page == pageNo}?'active':''">
                <a class="page-link" th:href="@{${#request.getRequestURI()}(page=${pageNo})}"  th:text="${pageNo}"></a>
            </li>
            </th:block>
        </th:block>


        <li class="page-item" th:classappend="${!jpaPageTool.isLastPage}?'disabled':''">
            <a class="page-link" th:href="@{${#request.getRequestURI()}(page=${jpaPageTool.page+1})}" aria-label="Next">
                <span aria-hidden="true">&raquo;</span>
                <span class="sr-only">Next</span>
            </a>
        </li>
    </ul>
</nav>

How do you pass the parameters of a conditional query?

Spencer Gibb
@spencergibb
Mar 02 15:12
@niyaode this is not the appropriate room
Tyler Van Gorder
@tkvangorder
Mar 02 21:32

@PatrickGotthard Sorry, a little late seeing your question. We managed to get things working with a combination of shutting down our tomcat connector using the following:

public class TomcatGracefullShutdownConnectorCustomizer implements TomcatConnectorCustomizer, ApplicationListener<ContextClosedEvent> {

    private volatile Connector connector;

    @Override
    public void onApplicationEvent(ContextClosedEvent event) {
        if (this.connector == null) {
            return;
        }
        this.connector.pause();
        Executor executor = this.connector.getProtocolHandler().getExecutor();
        if (executor instanceof ThreadPoolExecutor) {
            try {
                ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executor;
                threadPoolExecutor.shutdown();
                if (!threadPoolExecutor.awaitTermination(30, TimeUnit.SECONDS)) {
                        logger.warn("Tomcat thread pool did not shut down gracefully within 30 seconds. Proceeding with forceful shutdown");
                       threadPoolExecutor.shutdownNow();
                }
            }
            catch (InterruptedException ex) {
                Thread.currentThread().interrupt();
            }
        }        
}

Remember that even if you unregister with Eureka, each ribbon client might has a cached copy of the server list. By pausing the connector, you will get a socket error and then all downstream client calls (from your gateway) should retry on the next available node.

Marcos Barbero
@marcosbarbero
Mar 02 21:40
I can sound a little paranoid but the retry part should be present anyway, I mean, not just for de-registration but for the sake of a distributed system, the request can fail for a lot of reasons
Tyler Van Gorder
@tkvangorder
Mar 02 23:02
Right, you shouldn't have to build in a delay prior to shutting your service down. You shut it down, stop accepting new requests, wait for existing requests to finish, and exit. In the meantime, any future requests will failover to the next node.