> 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

Message Consumer for consuming from external message brokers

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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
