> ## Documentation Index
> Fetch the complete documentation index at: https://developer.upsun.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Kafka (Message queue service)

> Apache Kafka is an open-source stream-processing software platform.


It is a framework for storing, reading and analyzing streaming data. See the [Kafka documentation](https://kafka.apache.org/documentation) for more information.

## Supported versions

You can select the major and minor version.

Patch versions are applied periodically for bug fixes and other maintenance updates. By default, you get the latest available patches each time you deploy. If your project has a [maintenance window](https://developer.upsun.com/docs/core-concepts/build-deploy.md#maintenance-window) configured, Upsun Cloud applies patches only during that window. Upsun Cloud may still apply urgent or critical fixes outside of the maintenance window.

* 4.3
* 4.1
* 3.7
* 3.6

## Deprecated versions

The following versions are still available in your projects,
but they're at their end of life and are no longer receiving security updates from upstream.

*No deprecated versions.*

To ensure your project remains stable in the future,
switch to a [supported version](#supported-versions).

## Retired versions

The following versions have been retired and are no longer available.
If your project uses a retired version, you must update to a [supported version](#supported-versions).

* 3.4
* 3.2
* 2.7
* 2.6
* 2.5
* 2.4
* 2.3
* 2.2
* 2.1

## Relationship reference

For each service [defined via a relationship](#usage-example) to your application,
Upsun Cloud automatically generates corresponding environment variables within your application container,
in the `$<RELATIONSHIP-NAME>_<SERVICE-PROPERTY>` format.

Here is example information available through the [service environment variables](https://developer.upsun.com/docs/development/variables#service-environment-variables) themselves,
or through the [`PLATFORM_RELATIONSHIPS` environment variable](https://developer.upsun.com/docs/development/variables/use-variables#use-provided-variables).

You can obtain the complete list of available service environment variables in your app container by running `upsun ssh env`.

Note that the information about the relationship can change when an app is redeployed or restarted or the relationship is changed. So your apps should only rely on the [service environment variables](https://developer.upsun.com/docs/development/variables#service-environment-variables) directly rather than hard coding any values.

> [tab] Service environment variables
>
> &#x20;       KAFKA\_SERVICE=kafka
> &#x20;       KAFKA\_IP=123.456.78.90
> &#x20;       KAFKA\_HOSTNAME=azertyuiopqsdfghjklm.kafka.service.\_.eu-1.platformsh.site
> &#x20;       KAFKA\_CLUSTER=azertyuiop-main-7rqtwti
> &#x20;       KAFKA\_HOST=kafka.internal
> &#x20;       KAFKA\_REL=kafka
> &#x20;       KAFKA\_SCHEME=kafka
> &#x20;       KAFKA\_TYPE=kafka:\{\{version:kafka:latest}}
> &#x20;       KAFKA\_PORT=9092
> &#x20;    &#x20;

> [tab] `PLATFORM_RELATIONSHIPS` environment variable
>
> For some advanced use cases, you can use the [`PLATFORM_RELATIONSHIPS` environment variable](https://developer.upsun.com/docs/development/variables/use-variables#use-provided-variables).
> The structure of the `PLATFORM_RELATIONSHIPS` environment variable can be obtained by running `upsun relationships` in your terminal:
>
> &#x20;       \{
> &#x20;         "service": "kafka",
> &#x20;         "ip": "123.456.78.90",
> &#x20;         "hostname": "azertyuiopqsdfghjklm.kafka.service.\_.eu-1.platformsh.site",
> &#x20;         "cluster": "azertyuiop-main-7rqtwti",
> &#x20;         "host": "kafka.internal",
> &#x20;         "rel": "kafka",
> &#x20;         "scheme": "kafka",
> &#x20;         "type": "kafka:\{\{version:kafka:latest}}",
> &#x20;         "port": 9092
> &#x20;       }
> &#x20;    &#x20;
>
> Here is an example of how to gather [`PLATFORM_RELATIONSHIPS` environment variable](https://developer.upsun.com/docs/development/variables/use-variables#use-provided-variables) information in a [`.environment` file](https://developer.upsun.com/docs/development/variables/set-variables#when-to-use-env-files):
>
> ```bash .environment theme={null}
> # Decode the built-in credentials object variable.
> export RELATIONSHIPS_JSON="$(echo "$PLATFORM_RELATIONSHIPS" | base64 --decode)"
>
> # Set environment variables for individual credentials.
> export APP_KAFKA_HOST="$(echo "$RELATIONSHIPS_JSON" | jq -r '.kafka[0].host')"
> ```

## Usage example

### 1. Configure the service

To define the service, use the `kafka` type:


&#x20;   services:
&#x20;     \# The name of the service container. Must be unique within a project.
&#x20;     \<SERVICE\_NAME>:
&#x20;       type: kafka:\<VERSION>
&#x20;&#x20;

Note that changing the name of the service replaces it with a brand new service and all existing data is lost. Back up your data before changing the service.

### 2. Define the relationship

To define the relationship, use the following configuration:

> [tab] Using default endpoints
>
> &#x20;       applications:
> &#x20;         \# The name of the app container. Must be unique within a project.
> &#x20;         \<APP\_NAME>:
> &#x20;           \# Relationships enable access from this app to a given service.
> &#x20;           \# The example below shows simplified configuration leveraging a default service
> &#x20;           \# (identified from the relationship name) and a default endpoint.
> &#x20;           \# See the Application reference for all options for defining relationships and endpoints.
> &#x20;           relationships:
> &#x20;             \<SERVICE\_NAME>:
> &#x20;    &#x20;
>
> You can define `SERVICE_NAME` as you like, so long as it's unique between all defined services
> and matches in both the application and services configuration.
>
> The example above leverages [default endpoint](https://developer.upsun.com/docs/configure-apps/image-properties/relationships.md) configuration for relationships.
> That is, it uses default endpoints behind the scenes, providing a [relationship](https://developer.upsun.com/docs/configure-apps/image-properties/relationships.md)
> (the network address a service is accessible from) that is identical to the *name* of that service.
>
> Depending on your needs, instead of default endpoint configuration,
> you can use [explicit endpoint configuration](https://developer.upsun.com/docs/configure-apps/image-properties/relationships.md).
>
> With the above definition, the application container (`APP_NAME`) now has [access to the service](https://developer.upsun.com/docs/add-services/kafka.md) via the relationship `SERVICE_NAME` and its corresponding [service environment variables](https://developer.upsun.com/docs/development/variables#service-environment-variables)

> [tab] Using explicit endpoints
>
> &#x20;       applications:
> &#x20;         \# The name of the app container. Must be unique within a project.
> &#x20;         \<APP\_NAME>:
> &#x20;           \# Relationships enable access from this app to a given service.
> &#x20;           \# The example below shows configuration with an explicitly set service name and endpoint.
> &#x20;           \# See the Application reference for all options for defining relationships and endpoints.
> &#x20;           relationships:
> &#x20;             \<RELATIONSHIP\_NAME>:
> &#x20;               service: \<SERVICE\_NAME>
> &#x20;               endpoint: kafka
> &#x20;    &#x20;
>
> You can define `SERVICE_NAME` and `<RELATIONSHIP_NAME>` as you like, so long as it's unique between all defined services and relationships
> and matches in both the application and services configuration.
>
> The example above leverages [explicit endpoint](https://developer.upsun.com/docs/configure-apps/image-properties/relationships.md) configuration for relationships.
>
> Depending on your needs, instead of explicit endpoint configuration,
> you can use [default endpoint configuration](https://developer.upsun.com/docs/configure-apps/image-properties/relationships.md).
>
> With the above definition, the application container now has [access to the service](#usage-example) via the relationship `<RELATIONSHIP_NAME>` and its corresponding [service environment variables](https://developer.upsun.com/docs/development/variables#service-environment-variables).

### Example configuration

> [tab] Using default endpoints
>
> &#x20;       applications:
> &#x20;         \# The name of the app container. Must be unique within a project.
> &#x20;         myapp:
> &#x20;           \# Relationships enable access from this app to a given service.
> &#x20;           \# The example below shows simplified configuration leveraging a default service
> &#x20;           \# (identified from the relationship name) and a default endpoint.
> &#x20;           \# See the Application reference for all options for defining relationships and endpoints.
> &#x20;           relationships:
> &#x20;             kafka:
> &#x20;       services:
> &#x20;         \# The name of the service container. Must be unique within a project.
> &#x20;         kafka:
> &#x20;           type: kafka:\{\{version:kafka:latest}}

> [tab] Using explicit endpoints
>
> &#x20;       applications:
> &#x20;         \# The name of the app container. Must be unique within a project.
> &#x20;         myapp:
> &#x20;           \# Relationships enable access from this app to a given service.
> &#x20;           \# The example below shows configuration with an explicitly set service name and endpoint.
> &#x20;           \# See the Application reference for all options for defining relationships and endpoints.
> &#x20;           relationships:
> &#x20;             kafka:
> &#x20;               service: kafka
> &#x20;               endpoint: kafka
> &#x20;       services:
> &#x20;         \# The name of the service container. Must be unique within a project.
> &#x20;         kafka:
> &#x20;           type: kafka:\{\{version:kafka:latest}}

## Exporting Data

Kafka stores messages in on-disk topic partitions. You can export messages using the
`kafka-console-consumer` tool over an SSH session.

1. Open an SSH session to your app container (Kafka is not directly accessible via `tunnel:single`):

```bash Terminal theme={null}
upsun ssh
```

2. From the app container, list available topics:

```bash Terminal theme={null}
kafka-topics.sh \
  --bootstrap-server $KAFKA_HOST:$KAFKA_PORT \
  --list
```

3. Export all messages from a topic to a file:

```bash Terminal theme={null}
kafka-console-consumer.sh \
  --bootstrap-server $KAFKA_HOST:$KAFKA_PORT \
  --topic <TOPIC_NAME> \
  --from-beginning \
  --max-messages <NUMBER> \
  --timeout-ms 5000 \
  > /tmp/kafka-export-<TOPIC_NAME>.txt
```

4. Download the exported file:

```bash Terminal theme={null}
# From your local machine
upsun scp remote:/tmp/kafka-export-<TOPIC_NAME>.txt ./kafka-export-<TOPIC_NAME>.txt
```

The Kafka connection credentials (`KAFKA_HOST`, `KAFKA_PORT`) are available as
[service environment variables](https://developer.upsun.com/docs/development/variables#service-environment-variables)
inside the app container.

Note that Kafka is designed as a streaming platform, not a primary data store.
In most architectures, the authoritative copy of your data exists elsewhere (for example in a database),
and Kafka topics can be replayed or re-populated from that source.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.