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

# IMessage

> Defines the required composition of every Message published to the SimpleMessageBus.

## Definition

**Assembly:** CloudNimble.SimpleMessageBus.Core.dll

**Namespace:** CloudNimble.SimpleMessageBus.Core

## Syntax

```csharp theme={"dark"}
CloudNimble.SimpleMessageBus.Core.IMessage
```

## Summary

Defines the required composition of every Message published to the SimpleMessageBus.

## Remarks

All messages in the SimpleMessageBus system must implement this interface. The Id property ensures
that each message can be uniquely identified throughout its lifecycle, including during processing,
error handling, and when moved to poison queues.

## Examples

```csharp theme={"dark"}
public class OrderCreatedMessage : IMessage
{
    public Guid Id { get; set; } = Guid.NewGuid();
    public string OrderNumber { get; set; }
    public decimal TotalAmount { get; set; }
    public DateTime CreatedAt { get; set; }
}
```

## Properties

### <Icon icon="tag" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> Id <Badge color="orange">Abstract</Badge>

Gets or sets the unique identifier for this Message.

#### Syntax

```csharp theme={"dark"}
System.Guid Id { get; set; }
```

#### Property Value

Type: `System.Guid`
A [Guid](https://learn.microsoft.com/dotnet/api/system.guid) that uniquely identifies this message instance. This value should be set when
the message is created and remain constant throughout the message's lifetime.

#### Remarks

This identifier is used for tracking messages through the system, deduplication, and correlating
messages in poison queues with their original instances.

## Methods

### <Icon icon="puzzle-piece" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> CreateChild <Badge color="green">Extension</Badge>

<Note>Extension method from `CloudNimble.SimpleMessageBus.Core.MessageExtensions`</Note>

Creates a child message that inherits metadata and correlation from the parent.

#### Syntax

```csharp theme={"dark"}
public static TChild CreateChild<TChild>(CloudNimble.SimpleMessageBus.Core.IMessage parent) where TChild : CloudNimble.SimpleMessageBus.Core.MessageBase, new()
```

#### Parameters

| Name     | Type                                         | Description         |
| -------- | -------------------------------------------- | ------------------- |
| `parent` | `CloudNimble.SimpleMessageBus.Core.IMessage` | The parent message. |

#### Returns

Type: `TChild`
A new child message with inherited metadata and correlation.

#### Type Parameters

* `TChild` - The type of child message to create.

#### Examples

```csharp theme={"dark"}
// Create a child event that inherits filtered parent metadata
var shipmentRequested = message.CreateChild&lt;ShipmentRequested&gt;();
shipmentRequested.OrderId = message.OrderId;
shipmentRequested.Items = result.Items;

await publisher.PublishAsync(shipmentRequested);
```

### <Icon icon="puzzle-piece" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> LastRunSucceeded <Badge color="green">Extension</Badge>

<Note>Extension method from `CloudNimble.SimpleMessageBus.Core.MessageExtensions`</Note>

Checks if the current handler has already successfully processed this message.
This enables idempotent message processing.

#### Syntax

```csharp theme={"dark"}
public static bool LastRunSucceeded(CloudNimble.SimpleMessageBus.Core.IMessage message, string handlerTypeName = null)
```

#### Parameters

| Name              | Type                                         | Description                                                                 |
| ----------------- | -------------------------------------------- | --------------------------------------------------------------------------- |
| `message`         | `CloudNimble.SimpleMessageBus.Core.IMessage` | The message to check.                                                       |
| `handlerTypeName` | `string`                                     | The handler type name. If not provided, attempts to detect from call stack. |

#### Returns

Type: `bool`
`true` if this handler already ran successfully; otherwise, `false`.

#### Examples

```csharp theme={"dark"}
public async Task Handle(OrderCreated message, ILogger logger)
{
    if (message.LastRunSucceeded(GetType().Name))
    {
        logger.LogInformation("Order {OrderId} already processed successfully", message.Id);
        return;
    }

    // Process the message...
    message.UpdateResult(true, GetType().Name);
}
```

### <Icon icon="puzzle-piece" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> UpdateResult <Badge color="green">Extension</Badge>

<Note>Extension method from `CloudNimble.SimpleMessageBus.Core.MessageExtensions`</Note>

Updates the execution status for the current handler.

#### Syntax

```csharp theme={"dark"}
public static void UpdateResult(CloudNimble.SimpleMessageBus.Core.IMessage message, bool status, string handlerTypeName = null)
```

#### Parameters

| Name              | Type                                         | Description                                                                 |
| ----------------- | -------------------------------------------- | --------------------------------------------------------------------------- |
| `message`         | `CloudNimble.SimpleMessageBus.Core.IMessage` | The message to update.                                                      |
| `status`          | `bool`                                       | The execution status to record.                                             |
| `handlerTypeName` | `string`                                     | The handler type name. If not provided, attempts to detect from call stack. |

#### Examples

```csharp theme={"dark"}
public async Task Handle(OrderCreated message, ILogger logger)
{
    try
    {
        await ProcessOrder(message);
        message.UpdateResult(true, GetType().Name);
    }
    catch (Exception ex)
    {
        logger.LogError(ex, "Failed to process order");
        message.UpdateResult(false, GetType().Name);
        throw;
    }
}
```
