Tenez compte des initialisations suivantes de OkHttp et Rénovation:Okhttp ignore paramètre Dispatcher lorsqu'il est utilisé avec Retrofit RxJavaCallAdapterFactory
public static SomeServiceRestInterface newRestService(String apiUrl) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(apiUrl)
.client(createOkHttpClient())
.addCallAdapterFactory(RxJavaCallAdapterFactory.createWithScheduler(Schedulers.io()))
.addConverterFactory(createGsonConverter())
.build();
return retrofit.create(SomeServiceRestInterface.class);
}
private static OkHttpClient createOkHttpClient() {
Dispatcher dispatcher = new Dispatcher();
dispatcher.setMaxRequestsPerHost(1);
dispatcher.setMaxRequests(1);
OkHttpClient.Builder builder = new OkHttpClient.Builder()
.dispatcher(dispatcher).build()
}
Lors du test le reste appelle, je l'ai remarqué que Okhttp ne respecte pas les paramètres de setMaxRequestsPerHost ou setMaxRequests à tout. Voici le journal de 3 demandes envoyées simultanément:
23/07 04:14:22.668 [RxIoScheduler-4] DEBUG - --> POST https://XXX/1 http/1.1
23/07 04:14:22.668 [RxIoScheduler-4] DEBUG - Content-Length: 0
23/07 04:14:22.668 [RxIoScheduler-4] DEBUG - --> END POST (0-byte body)
23/07 04:14:22.672 [RxIoScheduler-7] DEBUG - --> POST https://XXX/2 http/1.1
23/07 04:14:22.673 [RxIoScheduler-7] DEBUG - Content-Length: 0
23/07 04:14:22.673 [RxIoScheduler-7] DEBUG - --> END POST (0-byte body)
23/07 04:14:22.676 [RxIoScheduler-6] DEBUG - --> POST https://XXX/3 http/1.1
23/07 04:14:22.677 [RxIoScheduler-6] DEBUG - Content-Length: 0
23/07 04:14:22.677 [RxIoScheduler-6] DEBUG - --> END POST (0-byte body)
où XXX est le même domaine, 1/2/3 sont des chemins différents. Je ne sais pas pourquoi, mais je pensais que cela a peut-être à voir avec le RxJava Scheduler défini dans addCallAdapterFactory.
Est-ce un bug? ou ai-je oublié quelque chose? J'utilise okhttp 3.4.1 et retrofit 2.1.0.
Avez-vous vérifié combien de clients http vous créez? –