> 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/modelling/microservices-php/message-consumer.md).

# Message Consumer

A Java team publishes events on RabbitMQ. Your PHP service needs to consume them — but they don't follow Ecotone's wire format. **Message Consumer** is the inbound adapter for arbitrary external messages, letting you connect to services written in any language or framework that share a broker with you. It's the counterpart to [Message Publisher](/modelling/microservices-php/message-publisher.md), and the right tool when you can't (or don't want to) put both ends on Ecotone's [Distributed Bus](/modelling/microservices-php/distributed-bus.md).

### Modules Providing Support

* [RabbitMQ Module](/modules/amqp-support-rabbitmq.md#message-consumer)

## Message Consumer Implementation

Consumer allow use to customize experience to fetch from chosen source:

```php
class Consumer
{
    // 1. Message Consumer
    #[MessageConsumer("consumer")]
    // 2. Method declaration
    public function execute(string $message, array $headers) : void
    {
        // do something with Message
        // if you have converter registered you can type hint exact type you expect
    }
}
```

1. `Message Consumer` - This tells Ecotone to consider given method to be message consumer.\
   First parameter is used as Consumer Name and this is how it will be run.
2. `Method declaration` - Depending how you define your [method declaration](/messaging/conversion/method-invocation.md), this way you will receive Message. In case of type hint for `string` then Message payload will be delivered to you as string (xml/json however it's formatted).

{% hint style="success" %}
Connecting Message Consumer to external broker, fetching message and converting it given class is done for you.\
\
All you need to do it set up [Extension Object ](#modules-providing-support)of given type in your [Service Context](/messaging/service-application-configuration.md) to use Message Consumer with given integration.
{% 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, and the optional `goal` query parameter:

```
GET https://docs.ecotone.tech/modelling/microservices-php/message-consumer.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
