# Message Channel

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 %}

### 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: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

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

The question should be specific, self-contained, and written in natural language.
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.
