[JAVA] Versuchen Sie, die Microsoft Azure SDK für SQL-API von Azure Cosmos DB Service 4.6 zu verwenden

Azure CosmosDB Java SDK Version 4.x wird 2020 veröffentlicht.

Die Verwendung wird im folgenden Dokument veröffentlicht, aber ich habe versucht, den Mindestcode für Hello World festzulegen. https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-sdk-java-v4

pom.xml

<!-- https://mvnrepository.com/artifact/com.azure/azure-cosmos -->
<dependency>
	<groupId>com.azure</groupId>
	<artifactId>azure-cosmos</artifactId>
	<version>4.6.0</version>
</dependency>

Sie können die Informationen, die Sie zum Herstellen einer Verbindung benötigen, im Azure-Portal abrufen.

image.png

package hello.cosmosdb;

import java.util.Iterator;

import com.azure.cosmos.CosmosClient;
import com.azure.cosmos.CosmosClientBuilder;
import com.azure.cosmos.CosmosContainer;
import com.azure.cosmos.CosmosDatabase;
import com.azure.cosmos.models.CosmosQueryRequestOptions;
import com.azure.cosmos.util.CosmosPagedIterable;
import com.fasterxml.jackson.databind.JsonNode;

/**
 * 
 * https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-sdk-java-v4
 * https://docs.microsoft.com/en-us/java/api/overview/azure/cosmos-readme?view=azure-java-stable
 * https://github.com/Azure-Samples/azure-cosmos-java-sql-api-samples/blob/367c796257feb37d2f8003a86fe51b0658fcf6ff/src/main/java/com/azure/cosmos/examples/queries/sync/QueriesQuickstart.java#L119
 * 
 * @author Hiroki Oya
 *
 */
public class HelloCosmosDbJavaSDK_V4 {

	private CosmosDatabase database;
	private CosmosContainer container;

	public void query() throws Exception {

		// [Azure Portal] - [your_cosmosdb] - [Keys] - [URI]
		String serviceEndpoint = "https://your_cosmosdb.documents.azure.com:443/";

		// [Azure Portal] - [your_cosmosdb] - [Keys] - [PRIMARY KEY | SECONDARY KEY]
		String key = "your_key_here";

		// [Azure Portal] - [your_cosmosdb] - [Data Explorer]
		String databaseId = "TEST";

		// [Azure Portal] - [your_cosmosdb] - [Data Explorer]
		String containerId = "container_for_test";

		String query = "SELECT * from c";

		CosmosClient client = new CosmosClientBuilder() //
				.endpoint(serviceEndpoint) //
				.key(key) //
				.buildClient();

		database = client.getDatabase(databaseId);
		container = database.getContainer(containerId);

		CosmosQueryRequestOptions options = new CosmosQueryRequestOptions();

		CosmosPagedIterable<JsonNode> page = container.queryItems(query, options, JsonNode.class);

		Iterator<JsonNode> it = page.iterator();

		while (it.hasNext()) {
			System.err.println(it.next());
		}

		client.close();

	}

	public static void main(String[] args) throws Exception {
		HelloCosmosDbJavaSDK_V4 h = new HelloCosmosDbJavaSDK_V4();
		h.query();
	}

}

Reference

Azure Cosmos DB Java SDK v4 for SQL API release notes and resources | Microsoft Docs https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-sdk-java-v4

Maven Repository: com.azure » azure-cosmos https://mvnrepository.com/artifact/com.azure/azure-cosmos

Azure CosmosDB Client Library for Java | Microsoft Docs https://docs.microsoft.com/en-us/java/api/overview/azure/cosmos-readme?view=azure-java-stable

azure-cosmos-java-sql-api-samples/QueriesQuickstart.java at 367c796257feb37d2f8003a86fe51b0658fcf6ff · Azure-Samples/azure-cosmos-java-sql-api-samples · GitHub https://github.com/Azure-Samples/azure-cosmos-java-sql-api-samples/blob/367c796257feb37d2f8003a86fe51b0658fcf6ff/src/main/java/com/azure/cosmos/examples/queries/sync/QueriesQuickstart.java

Azure Cosmos DB Workshop - Querying in Azure Cosmos DB https://cosmosdb.github.io/labs/dotnet/labs/03-querying_in_azure_cosmosdb.html

das ist alles.

Recommended Posts

Versuchen Sie, die Microsoft Azure SDK für SQL-API von Azure Cosmos DB Service 4.6 zu verwenden
Versuchen Sie eine ähnliche Suche in der Bildsuche mit dem Java SDK [Suche]
Versuchen Sie, S3Proxy mit Microsoft Azure Blob Storage zu verwenden
Wählen Sie * aus dem Java SDK in Azure Cosmos DB
Löschen Sie alle aus dem Java SDK in Azure CosmosDB
Versuchen Sie, viele Daten in Cosmos DB zu speichern
Versuchen Sie Spark Submit to EMR mit AWS SDK für Java