Skip to content

Latest commit

 

History

History
81 lines (64 loc) · 2.42 KB

File metadata and controls

81 lines (64 loc) · 2.42 KB
description Kafka message channels for async processing in Ecotone

Message Channel

To understand the use case behind Message Channels read Asynchronous Processing section for Application level processing and Distributed Bus section for cross application communication.

Message Channel

To create Kafka Backed Message Channel, we need to create Service Context.

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:

#[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:

#[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:

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