View Javadoc
1   /*
2    * Copyright (c) 2023. Roland T. Lichti, Kaiserpfalz EDV-Service.
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program.  If not, see <https://www.gnu.org/licenses/>.
16   */
17  
18  package de.kaiserpfalzedv.services.eansearch.client;
19  
20  import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
21  
22  import java.util.Set;
23  
24  import org.springframework.cloud.openfeign.FeignClient;
25  import org.springframework.web.bind.annotation.GetMapping;
26  import org.springframework.web.bind.annotation.RequestParam;
27  
28  import de.kaiserpfalzedv.services.eansearch.model.EanData;
29  import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
30  import io.github.resilience4j.retry.annotation.Retry;
31  import io.micrometer.core.annotation.Counted;
32  import io.micrometer.core.annotation.Timed;
33  
34  /**
35   * <p>EanSearchClient -- The client for accessing the web service.</p>
36   *
37   *
38   * @author rlichti {@literal <rlichti@kaiserpfalz-edv.de>}
39   * @since 3.0.0  2023-01-17
40   */
41  @FeignClient(name = "eansearch", configuration = EanSearchClientConfig.class, path = "/api")
42  public interface EanSearchClient {
43      @GetMapping(produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
44      @Retry(name = "eansearch")
45      @CircuitBreaker(name = "eansearch")
46      @Timed("ean-search.lookup.ean.time")
47      @Counted("ean-search.lookup.ean.count")
48      // @Retry(delay = 2000, maxDuration = 6000, retryOn = {EanSearchTooManyRequestsException.class, RateLimitException.class}, abortOn = EanSearchException.class)
49      // @CircuitBreaker(failOn = EanSearchException.class, requestVolumeThreshold = 5)
50      Set<EanData> barcodeLookupEAN(@RequestParam("ean") final String ean13);
51  
52      @GetMapping(produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
53      @Retry(name = "eansearch")
54      @CircuitBreaker(name = "eansearch")
55      @Timed("ean-search.lookup.upc.time")
56      @Counted("ean-search.lookup.upc.count")
57      // @Retry(delay = 2000, maxDuration = 6000, retryOn = {EanSearchTooManyRequestsException.class, RateLimitException.class}, abortOn = EanSearchException.class)
58      // @CircuitBreaker(failOn = EanSearchException.class, requestVolumeThreshold = 5)
59      Set<EanData> barcodeLookupUPC(@RequestParam("upc") final String upc12);
60  
61      @GetMapping(produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
62      @Retry(name = "eansearch")
63      @CircuitBreaker(name = "eansearch")
64      @Timed("ean-search.lookup.isbn.time")
65      @Counted("ean-search.lookup.isbn.count")
66      Set<EanData> barcodeLookupISBN(@RequestParam("isbn") final String isbn10);
67  }