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

# KafkaProcessor

> Processes messages from Apache Kafka and dispatches them to registered message handlers.

## Definition

**Assembly:** CloudNimble.SimpleMessageBus.Dispatch.Kafka.dll

**Namespace:** CloudNimble.SimpleMessageBus.Dispatch.Kafka

**Inheritance:** System.Object

## Syntax

```csharp theme={"dark"}
CloudNimble.SimpleMessageBus.Dispatch.Kafka.KafkaProcessor
```

## Summary

Processes messages from Apache Kafka and dispatches them to registered message handlers.

## Remarks

This processor integrates with Azure WebJobs to automatically trigger message processing
when messages arrive in a Kafka topic. It handles message deserialization, lifecycle
management, and provides proper logging and dependency injection scope for each message.

Unlike Azure Storage Queues, Kafka does not require explicit message deletion. The WebJobs
Kafka extension automatically commits offsets after successful processing. If processing
fails, the message will be reprocessed based on the consumer group's offset configuration.

## Examples

```csharp theme={"dark"}
Host.CreateDefaultBuilder()
    .ConfigureServices(services =&gt;
    {
        services.AddSingleton&lt;IMessageHandler, MyMessageHandler&gt;();
    })
    .UseKafkaProcessor(options =&gt;
    {
        options.BrokerList = "localhost:9092";
        options.ConsumerGroup = "my-consumer";
    })
    .UseOrderedMessageDispatcher()
    .Build()
    .Run();
```

## Constructors

### <Icon icon="hammer" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> .ctor

Creates a new instance of [KafkaProcessor](/simplemessagebus/api-reference/CloudNimble/SimpleMessageBus/Dispatch/Kafka/KafkaProcessor).

#### Syntax

```csharp theme={"dark"}
public KafkaProcessor(CloudNimble.SimpleMessageBus.Dispatch.IMessageDispatcher dispatcher, Microsoft.Extensions.DependencyInjection.IServiceScopeFactory serviceScopeFactory)
```

#### Parameters

| Name                  | Type                                                            | Description                                           |
| --------------------- | --------------------------------------------------------------- | ----------------------------------------------------- |
| `dispatcher`          | `CloudNimble.SimpleMessageBus.Dispatch.IMessageDispatcher`      | The message dispatcher to route messages to handlers. |
| `serviceScopeFactory` | `Microsoft.Extensions.DependencyInjection.IServiceScopeFactory` | Factory for creating DI scopes per message.           |

#### Exceptions

| Exception               | Description                                                |
| ----------------------- | ---------------------------------------------------------- |
| `ArgumentNullException` | Thrown when *dispatcher* or *serviceScopeFactory* is null. |

### <Icon icon="hammer" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> .ctor <Badge color="gray">Inherited</Badge>

<Note>Inherited from `object`</Note>

#### Syntax

```csharp theme={"dark"}
public Object()
```

## Methods

### <Icon icon="code-fork" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> Equals <Badge color="gray">Inherited</Badge> <Badge color="orange">Virtual</Badge>

<Note>Inherited from `object`</Note>

#### Syntax

```csharp theme={"dark"}
public virtual bool Equals(object obj)
```

#### Parameters

| Name  | Type      | Description |
| ----- | --------- | ----------- |
| `obj` | `object?` | -           |

#### Returns

Type: `bool`

### <Icon icon="thumbtack" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> Equals <Badge color="gray">Inherited</Badge>

<Note>Inherited from `object`</Note>

#### Syntax

```csharp theme={"dark"}
public static bool Equals(object objA, object objB)
```

#### Parameters

| Name   | Type      | Description |
| ------ | --------- | ----------- |
| `objA` | `object?` | -           |
| `objB` | `object?` | -           |

#### Returns

Type: `bool`

### <Icon icon="code-fork" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> GetHashCode <Badge color="gray">Inherited</Badge> <Badge color="orange">Virtual</Badge>

<Note>Inherited from `object`</Note>

#### Syntax

```csharp theme={"dark"}
public virtual int GetHashCode()
```

#### Returns

Type: `int`

### <Icon icon="function" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> GetType <Badge color="gray">Inherited</Badge>

<Note>Inherited from `object`</Note>

#### Syntax

```csharp theme={"dark"}
public System.Type GetType()
```

#### Returns

Type: `System.Type`

### <Icon icon="function" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> MemberwiseClone <Badge color="gray">Inherited</Badge>

<Note>Inherited from `object`</Note>

#### Syntax

```csharp theme={"dark"}
protected internal object MemberwiseClone()
```

#### Returns

Type: `object`

### <Icon icon="function" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> ProcessKafkaMessage

Processes a message from the Kafka topic and dispatches it to registered handlers.

#### Syntax

```csharp theme={"dark"}
public System.Threading.Tasks.Task ProcessKafkaMessage(Microsoft.Azure.WebJobs.Extensions.Kafka.KafkaEventData<string> kafkaEvent, Microsoft.Extensions.Logging.ILogger logger)
```

#### Parameters

| Name         | Type                                                              | Description                                        |
| ------------ | ----------------------------------------------------------------- | -------------------------------------------------- |
| `kafkaEvent` | `Microsoft.Azure.WebJobs.Extensions.Kafka.KafkaEventData<string>` | The Kafka event containing the message payload.    |
| `logger`     | `Microsoft.Extensions.Logging.ILogger`                            | The logger instance for this processing operation. |

#### Returns

Type: `System.Threading.Tasks.Task`
A [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task) representing the asynchronous operation.

#### Remarks

This method is triggered automatically by the WebJobs Kafka extension when messages
arrive. It deserializes the message envelope, sets up processing context, and
dispatches to handlers.

The offset is automatically committed after successful processing. If an exception
is thrown, the offset is not committed and the message will be reprocessed.

### <Icon icon="thumbtack" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> ReferenceEquals <Badge color="gray">Inherited</Badge>

<Note>Inherited from `object`</Note>

#### Syntax

```csharp theme={"dark"}
public static bool ReferenceEquals(object objA, object objB)
```

#### Parameters

| Name   | Type      | Description |
| ------ | --------- | ----------- |
| `objA` | `object?` | -           |
| `objB` | `object?` | -           |

#### Returns

Type: `bool`

### <Icon icon="code-fork" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> ToString <Badge color="gray">Inherited</Badge> <Badge color="orange">Virtual</Badge>

<Note>Inherited from `object`</Note>

#### Syntax

```csharp theme={"dark"}
public virtual string ToString()
```

#### Returns

Type: `string?`

## Related APIs

* CloudNimble.SimpleMessageBus.Dispatch.IQueueProcessor
