Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. // provide a RestClientFactory for custom configuration on the internally created REST client
  2. // i only show the setMaxRetryTimeoutMillis for illustration purposes, the actual code will use HTTP cutom callback
  3. esSinkBuilder.setRestClientFactory(
  4. restClientBuilder -> {
  5. restClientBuilder.setMaxRetryTimeoutMillis(10)
  6. }
  7. )
  8.  
  9. // provide a RestClientFactory for custom configuration on the internally created REST client// provide a RestClientFactory for custom configuration on the internally created REST client
  10. import org.apache.http.auth.AuthScope
  11. import org.apache.http.auth.UsernamePasswordCredentials
  12. import org.apache.http.client.CredentialsProvider
  13. import org.apache.http.impl.client.BasicCredentialsProvider
  14. import org.apache.http.impl.nio.client.HttpAsyncClientBuilder
  15. import org.elasticsearch.client.RestClientBuilder
  16. // provide a RestClientFactory for custom configuration on the internally created REST client// provide a RestClientFactory for custom configuration on the internally created REST client
  17.  
  18. esSinkBuilder.setRestClientFactory((restClientBuilder) => {
  19. def foo(restClientBuilder) = restClientBuilder.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
  20. override def customizeHttpClient(httpClientBuilder: HttpAsyncClientBuilder): HttpAsyncClientBuilder = { // elasticsearch username and password
  21. val credentialsProvider = new BasicCredentialsProvider
  22. credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(es_user, es_password))
  23. httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)
  24. }
  25. })
  26.  
  27. foo(restClientBuilder)
  28. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement