> 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/messaging/multi-tenancy-support/different-scenarios/accessing-current-tenant-in-message-handler.md).

# Accessing Current Tenant in Message Handler

For specific scenarios we may need to be aware of Tenant’s context in which execution is done. For example given Tenant may have luxury Shop where delivery should happen right away after order is made, where for other Tenant time does not matter.

In case of Ecotone, whatever we send via Message Headers (Metadata) is accessible for us on the Message Handler level. This way depending on the need we can ignore or access given metadata. And as we send Tenant name via Message Headers, we can access it in case of need:

```php
final readonly class OrderService
{
    public function __construct(private FastDelivery $fastDelivery) {}
    
    #[CommandHandler]
    public function handle(
      PlaceOrder $command,
      #[Header('tenant')] $tenantName
    )
    {
        if ($this->fastDelivery->isEnabled($tenantName)) {
            // Place order differently for Premium Tenant    
        }else {
            // Do normal order process
        }
    }
}
```

{% hint style="success" %}
We can access any Message Header in our Message Handlers. This means, whatever Metadata we will pass with Command/Query/Event (e.g. User Id, User Role, HTTP Domain from which request is made etc), we can then access it when needed.
{% endhint %}


---

# 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 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/messaging/multi-tenancy-support/different-scenarios/accessing-current-tenant-in-message-handler.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.
