# Client (/sdks/java/reference/client)



The Java SDK splits messaging APIs across focused clients: pub/sub (`PubSubClient`), queues (`QueuesClient`), and commands/queries (`CQClient`). All extend shared connection management and implement `AutoCloseable`.

## Package [#package]

```xml
<dependency>
    <groupId>io.kubemq.sdk</groupId>
    <artifactId>kubemq-sdk-Java</artifactId>
    <version>3.1.1</version>
</dependency>
```

Requires Java 11+.

## Client classes [#client-classes]

| Class          | Package                | Patterns             |
| -------------- | ---------------------- | -------------------- |
| `PubSubClient` | `io.kubemq.sdk.pubsub` | Events, Events Store |
| `QueuesClient` | `io.kubemq.sdk.queues` | Queues               |
| `CQClient`     | `io.kubemq.sdk.cq`     | Commands, Queries    |

### Builder construction [#builder-construction]

```java
PubSubClient pub = PubSubClient.builder()
    .address("localhost:50000")
    .clientId("java-pub")
    .build();

QueuesClient queues = QueuesClient.builder()
    .address("localhost:50000")
    .clientId("java-q")
    .build();

CQClient cq = CQClient.builder()
    .address("localhost:50000")
    .clientId("java-cq")
    .build();
```

**Parameters (typical builder fields):**

| Name                 | Type                 | Required | Description                   |
| -------------------- | -------------------- | -------- | ----------------------------- |
| `address`            | `String`             | Yes      | `host:port` for the broker    |
| `clientId`           | `String`             | Yes      | Stable ID for this process    |
| `authToken`          | `String`             | No       | Bearer token                  |
| TLS / cert fields    | various              | No       | Mutual TLS and trust material |
| `reconnectionConfig` | `ReconnectionConfig` | No       | Backoff and retry tuning      |

**Returns:** Concrete client instance ready for RPCs.

**Throws:** `KubeMQException` — validation or connection failures during `build()`.

## Lifecycle [#lifecycle]

Prefer try-with-resources because each client implements `AutoCloseable`:

```java
try (PubSubClient client = PubSubClient.builder().address("localhost:50000").clientId("demo").build()) {
    // use client
}
```

## Quick Usage [#quick-usage]

```java title="App.java"
try (PubSubClient pub = PubSubClient.builder()
        .address("localhost:50000")
        .clientId("reference-demo")
        .build()) {
    // Events APIs live on PubSubClient — see Events reference page
}
```

## See Also [#see-also]

* [Connection Examples](/sdks/java/how-to/connection/)
* Concepts
* [Java SDK Getting Started](/sdks/java)
