> For the complete documentation index, see [llms.txt](https://docs.ecotone.tech/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ecotone.tech/modules/kafka-support/message-channel.md).

# Message Channel

Kafka message channels for async processing in Ecotone

To understand the use case behind Message Channels read [Asynchronous Processing](/modelling/asynchronous-handling/asynchronous-message-handlers.md) section for Application level processing and [Distributed Bus](/modelling/microservices-php/distributed-bus/distributed-bus-with-service-map.md) section for cross application communication.

## Message Channel

To create Kafka Backed [Message Channel](/modelling/asynchronous-handling.md), we need to create [Service Context](/messaging/service-application-configuration.md).

```php
class MessagingConfiguration
{
    #[ServiceContext] 
    public function orderChannel()
    {
        return KafkaMessageChannelBuilder::create("orders");
    }
}
```

Now `orders` channel will be available in our Messaging System.

{% hint style="success" %}
Message Channels simplify to the maximum integration with Message Broker.\
From application perspective all we need to do, is to provide channel implementation.\
Ecotone will take care of whole publishing and consuming part.
{% endhint %}

### High Throughput Publishing (Enterprise)

Messages published within the same execution scope can be pipelined to the Broker with deferred delivery reports, multiplying publishing throughput:

```php
#[ServiceContext] 
public function orderChannel()
{
    return KafkaMessageChannelBuilder::create("orders")
        ->withHighThroughputPublishing();
}
```

Both mechanisms can be tuned individually with `batchPublishing`, `nonBlockingConfirmation` and `confirmationTimeoutInMilliseconds`.

Read more in [Non-blocking Batched Delivery](/modelling/asynchronous-handling/non-blocking-batched-delivery.md).

### Customize Topic Name

By default the queue name will follow channel name, which in above example will be "orders".\
However we can use "orders" as reference name in our Application, yet name queue differently:

```php
#[ServiceContext] 
public function orderChannel()
{
    return KafkaMessageChannelBuilder::create(
        channelName: "orders",
        topicName: "crm_orders"
    );
}
```

### Customize Group Id

We can also customize the group id, which by default following channel name:

```php
#[ServiceContext] 
public function orderChannel()
{
    return KafkaMessageChannelBuilder::create(
        channelName: "orders",
        groupId: "crm_application"
    );
}
```

{% hint style="warning" %}
Position of Message Consumer is tracked against given group id.. Depending on retention policy, changing group id for existing Message Channel may result in re-delivering messages.
{% endhint %}

## Final Failure Strategy

To define [Final Failure Strategy](/modelling/recovering-tracing-and-monitoring/resiliency/final-failure-strategy.md):

```php
#[ServiceContext] 
public function orderChannel()
{
    return KafkaMessageChannelBuilder::create(
        channelName: "orders",
        groupId: "crm_application"
    )
        ->withFinalFailureStrategy(FinalFailureStrategy::RESEND);
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.ecotone.tech/modules/kafka-support/message-channel.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
