Step 1: Local Setup¶
Before writing code, you need to prepare your development environment and Azure resources.
This tutorial walks these steps in order:
flowchart TD
START["Step 1: Local Setup"]
N1["Prerequisites"]
N2["1. Create ACS Resource"]
N3["2. Initialize Maven Project"]
N4["3. Add Dependencies"]
N5["4. Set Environment Variables"]
N6["5. Verify Setup"]
START --> N1
N1 --> N2
N2 --> N3
N3 --> N4
N4 --> N5
N5 --> N6 Prerequisites¶
- JDK 8+: Ensure you have a Java Development Kit installed.
- Maven: Installed and added to your system path.
- Azure CLI: Useful for resource management (optional but recommended).
1. Create ACS Resource¶
Use the Azure Portal or CLI to create an Azure Communication Services resource:
az communication create --name "MyACSResource" --location "Global" --data-location "United States" --resource-group "MyResourceGroup"
| Command | Purpose |
|---|---|
az communication create | Creates an Azure Communication Services resource. |
--name "MyACSResource" | Names the ACS resource to create. |
--location "Global" | Sets the resource location (ACS resources are Global). |
--data-location "United States" | Sets the immutable region where data at rest is stored. |
--resource-group "MyResourceGroup" | Places the resource in the named resource group. |
Once created, navigate to the Keys section and copy the Connection String.
2. Initialize Maven Project¶
Create a new directory and initialize a Maven project:
mvn archetype:generate -DgroupId=com.communication.quickstart -DartifactId=communication-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
3. Add Dependencies¶
Update your pom.xml to include the ACS Identity SDK:
<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-communication-identity</artifactId>
<version>1.5.0</version>
</dependency>
<!-- Core library for common types -->
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core</artifactId>
<version>1.45.0</version>
</dependency>
</dependencies>
4. Set Environment Variables¶
Avoid hardcoding connection strings. Set an environment variable:
5. Verify Setup¶
Create a file named App.java and add the following code to verify you can connect to your resource:
package com.communication.quickstart;
import com.azure.communication.identity.CommunicationIdentityClient;
import com.azure.communication.identity.CommunicationIdentityClientBuilder;
import com.azure.communication.identity.models.CommunicationUserIdentifier;
public class App {
public static void main(String[] args) {
String connectionString = System.getenv("COMMUNICATION_SERVICES_CONNECTION_STRING");
if (connectionString == null || connectionString.isEmpty()) {
System.err.println("Please set the COMMUNICATION_SERVICES_CONNECTION_STRING environment variable.");
return;
}
CommunicationIdentityClient client = new CommunicationIdentityClientBuilder()
.connectionString(connectionString)
.buildClient();
CommunicationUserIdentifier user = client.createUser();
System.out.println("Successfully created user with ID: " + user.getId());
}
}
Run the application:
Next Step¶
Now that your environment is ready, let's Send an SMS.