Implementation:A2aproject A2a java TransportProtocol
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Spec, Protocol_Design |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Concrete enum defining the three transport protocols supported by the A2A Java SDK: JSON-RPC, gRPC, and HTTP+JSON (REST).
Description
The `TransportProtocol` enum maps between string representations of transport protocols (used in AgentCard JSON serialization and configuration properties) and strongly-typed enum constants. It provides `fromString()` for parsing protocol strings and `asString()` for serialization.
The three supported transports are:
- JSONRPC — JSON-RPC 2.0 over HTTP; the primary, most widely supported transport
- GRPC — gRPC binary protocol using Protocol Buffers; high-performance with streaming
- HTTP_JSON — RESTful HTTP with JSON payloads; maps to the string "HTTP+JSON"
Usage
- Configuring transport selection: Use `TransportProtocol.fromString()` to parse a config property into an enum constant.
- Building AgentInterface: Pass `protocol.asString()` as the protocol binding when creating `AgentInterface` entries for an AgentCard.
- Transport negotiation: The enum constants are used by `ClientBuilder` to match client transports against server-supported interfaces.
Code Reference
Source Location
- Repository: a2a-java
- File: `spec/src/main/java/org/a2aproject/sdk/spec/TransportProtocol.java`
- Lines: L28-90
Signature
public enum TransportProtocol {
JSONRPC("JSONRPC"),
GRPC("GRPC"),
HTTP_JSON("HTTP+JSON");
public String asString();
public static TransportProtocol fromString(String transport);
}
Import
import org.a2aproject.sdk.spec.TransportProtocol;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| transport | String | Yes | Protocol string: "JSONRPC", "GRPC", or "HTTP+JSON" |
Outputs
| Name | Type | Description |
|---|---|---|
| fromString() returns | TransportProtocol | Enum constant matching the input string |
| asString() returns | String | String representation for JSON serialization |
| Invalid input | IllegalArgumentException | Thrown if transport string is not recognized |
Usage Examples
Parsing from Configuration
import org.a2aproject.sdk.spec.TransportProtocol;
import org.eclipse.microprofile.config.inject.ConfigProperty;
// Parse transport protocol from a config property
@ConfigProperty(name = "quarkus.agentcard.protocol", defaultValue = "JSONRPC")
String protocolStr;
TransportProtocol protocol = TransportProtocol.fromString(protocolStr);
Building an AgentInterface
import org.a2aproject.sdk.spec.TransportProtocol;
import org.a2aproject.sdk.spec.AgentInterface;
// Create a transport interface for the AgentCard
TransportProtocol protocol = TransportProtocol.GRPC;
String url = switch (protocol) {
case GRPC -> "localhost:9000";
case JSONRPC, HTTP_JSON -> "http://localhost:9999";
};
AgentInterface iface = new AgentInterface(protocol.asString(), url);
Related Pages
Implements Principle
- Principle:A2aproject_A2a_java_Agent_Card_Advertisement
- Principle:A2aproject_A2a_java_Transport_Protocol_Negotiation
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment