Я пытаюсь вывести цены на криптовалюты через API CryptoCompare с интервалом в одну минуту.Во-первых, простое приложение Spring Boot делает это один раз без проблем, и я получаю следующий ответ, как и ожидалось:
{
"BTC": {"USD": 3949.37},
"XRP": {"USD": 0.3289},
"ETH": {"USD": 146.59},
"LTC": {"USD": 50.81},
"XMR": {"USD": 51.54}
}
Однако, когда я помещаю этот идентичный код в планировщик Spring Boot, я получаю:
java.net.UnknownHostException: min-application.api.cryptocompare.com
Точка взлома такова:
Response response = client.newCall(request).execute();
Начало этого класса здесь:
@Component
public class ScheduledTask {
static String url = "https://min-api.cryptocompare.com/data/pricemulti?fsyms=BTC,XRP,XMR,LTC,ETH&tsyms=USD&api_key=***************************";
static OkHttpClient client = new OkHttpClient();
@Autowired
private CryptoPriceService cryptoPriceService;
@Scheduled(fixedRate = 500)
public void getPricesNow () throws IOException {
Request request = new Request.Builder()
.url(url)
.build();
Response response = client.newCall(request).execute();
И это трассировка стека:
java.net.UnknownHostException: min-application.api.cryptocompare.com
at java.net.InetAddress.getAllByName0(InetAddress.java:1281) ~[na:1.8.0_201]
at java.net.InetAddress.getAllByName(InetAddress.java:1193) ~[na:1.8.0_201]
at java.net.InetAddress.getAllByName(InetAddress.java:1127) ~[na:1.8.0_201]
at okhttp3.Dns$1.lookup(Dns.java:39) ~[okhttp-3.8.1.jar:na]
at okhttp3.internal.connection.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:171) ~[okhttp-3.8.1.jar:na]
at okhttp3.internal.connection.RouteSelector.nextProxy(RouteSelector.java:137) ~[okhttp-3.8.1.jar:na]
at okhttp3.internal.connection.RouteSelector.next(RouteSelector.java:82) ~[okhttp-3.8.1.jar:na]
at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:171) ~[okhttp-3.8.1.jar:na]
at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:121) ~[okhttp-3.8.1.jar:na]
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:100) ~[okhttp-3.8.1.jar:na]
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42) ~[okhttp-3.8.1.jar:na]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) ~[okhttp-3.8.1.jar:na]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) ~[okhttp-3.8.1.jar:na]
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93) ~[okhttp-3.8.1.jar:na]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) ~[okhttp-3.8.1.jar:na]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) ~[okhttp-3.8.1.jar:na]
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) ~[okhttp-3.8.1.jar:na]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) ~[okhttp-3.8.1.jar:na]
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120) ~[okhttp-3.8.1.jar:na]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) ~[okhttp-3.8.1.jar:na]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) ~[okhttp-3.8.1.jar:na]
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185) ~[okhttp-3.8.1.jar:na]
at okhttp3.RealCall.execute(RealCall.java:69) ~[okhttp-3.8.1.jar:na]
at application.tasks.ScheduledTasks.getPricesNow(ScheduledTasks.java:36) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_201]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_201]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_201]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_201]
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_201]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [na:1.8.0_201]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_201]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [na:1.8.0_201]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_201]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_201]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_201]
Не уверен, что это что-то значит, но вот ответ от nslookup:
$ nslookup min-application.api.cryptocompare.com
Server: 127.0.0.53
Address: 127.0.0.53#53
Non-authoritative answer:
*** Can't find min-application.api.cryptocompare.com: No answer
Я должен повторить, что могу получить ожидаемыйответ от первого приложения, а также от Почтальона.