I've created a simple Java project. And added the JARs to the classpath. In the file BulkImport.java, I'm trying to connect to the Azure Cosmos DB. However, I'm running into the following error.
Warning : [main] WARN com.microsoft.azure.documentdb.GlobalEndpointManager - Failed to retrieve database account information. com.microsoft.azure.documentdb.DocumentClientException: java.net.UnknownHostException: This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server.
BulkImport.java
public class BulkImport {
//public static final Logger LOGGER = LoggerFactory.getLogger(BulkImport.class);
public static final String ENDPOINT = "https://<xxxx>.documents.azure.com:443/";
public static final String PRIMARY_KEY = xxxx
public static final String DATABASE = "xxxx"
public static final String CONTAINER = "xxxx";
public static final String PARTITION_KEY = "/id";
public static final int THROUGHPUT = 10000;
public static void main(String args[]) throws Exception {
executeBulkImport();
System.out.print("Done");
}
public static void executeBulkImport() throws Exception
{
ConnectionPolicy connectionPolicy = new ConnectionPolicy();
connectionPolicy.setMaxPoolSize(1000);
// Below line is giving the error
DocumentClient client = new DocumentClient(ENDPOINT, PRIMARY_KEY, connectionPolicy, ConsistencyLevel.Session);
DocumentCollection collection = Utilities.createEmptyCollectionIfNotExists(client, DATABASE, CONTAINER, PARTITION_KEY, THROUGHPUT);
ArrayList<String> list = new ArrayList<String>();
JSONParser jsonParser = new JSONParser();
try (FileReader reader = new FileReader("C:\\samplejson.json")) {
Object obj = jsonParser.parse(reader);
JSONArray jsonArray = (JSONArray) obj;
System.out.println(jsonArray);
if (jsonArray != null) {
int len = jsonArray.size();
for (int i=0;i<len;i++){
list.add(jsonArray.get(i).toString());
}
}
System.out.println(list.get(0));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
client.getConnectionPolicy().getRetryOptions().setMaxRetryWaitTimeInSeconds(30);
client.getConnectionPolicy().getRetryOptions().setMaxRetryAttemptsOnThrottledRequests(9);
// Builder pattern
DocumentBulkExecutor.Builder bulkExecutorBuilder = DocumentBulkExecutor.builder().from(client, DATABASE, CONTAINER,
collection.getPartitionKey(), 20000);
try {
DocumentBulkExecutor bulkExecutor = bulkExecutorBuilder.build();
client.getConnectionPolicy().getRetryOptions().setMaxRetryWaitTimeInSeconds(0);
client.getConnectionPolicy().getRetryOptions().setMaxRetryAttemptsOnThrottledRequests(0);
BulkImportResponse bulkImportResponse = bulkExecutor.importAll(list, false, false, null);
System.out.println(bulkImportResponse.getNumberOfDocumentsImported());
} catch (Exception e) {
e.printStackTrace();
}
client.close();
}
}
Please help me understand the issue.
dig <xxxx>.documents.azure.com? Is there maybe a proxy you have to go through? Quite often the case in corporate environments.dig <the address you'd like to connect to>. Just google it. linode.com/docs/networking/dns/…nslookup. It is returning back the IP Address!