# Interface KeyExtractor (1.16.5)

1.16.5 (latest) 1.16.2 1.15.21 1.14.8 1.13.8 1.12.22 1.11.2 1.10.0 1.9.4 1.8.0 1.7.1 1.6.3 1.5.5 1.4.12

    public interface KeyExtractor

A KeyExtractor can extract the Pub/Sub Lite 'key' field used for message routing from a
PubsubMessage. It will by default use the ordering_key field directly for this if it exists.

An empty ByteString implies that the message should have no ordering key.

## Static Fields

### DEFAULT

    public static final KeyExtractor DEFAULT

An extractor that gets the routing key from the ordering key field.

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-pubsublite/latest/com.google.cloud.pubsublite.cloudpubsub.KeyExtractor` |   |

## Methods

### extractKey(PubsubMessage message)

    public abstract ByteString extractKey(PubsubMessage message)

Extract the ByteString routing key from a PubsubMessage.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `message` | `com.google.pubsub.v1.PubsubMessage` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.ByteString.html` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.ApiException.html` |   |