---
schema_version: "1"
id: 4cbd913a87ff731781c20203a61ea93aaa069c933773ac4a9f093b835dabb9dd
title: Listen For A Reply
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/amqp-connector/latest/amqp-publish-consume.md
canonical_url: https://docs.mulesoft.com/amqp-connector/latest/amqp-publish-consume
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 9542b3912314db40d914112f929f49ae9226ef3fea1cc62e4ea64d5cb68780cf
description: MuleSoft Documentation Site
release: "1.9"
latest: true
---
---
product: AMQP Connector
version: 1.9
is-latest-version: true
---

# Listen For A Reply

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

Request and Reply is a very common pattern between applications. AMQP Connector provides an
operation specially designed for this, called `publish-consume`. The `publish-consume` operation
enables you to publish a message to any exchange, and then wait for a reply on a different
destination.

When using this operation, the `replyTo` property of the outgoing message will contain the ID of the
queue at which your app will be waiting for a response. This destination may be a well-known
destination, or it may be a temporary queue created on the fly with the only purpose of receiving a
single response message.

Finally, the result of the operation will be the message received as a response, with exactly the
same structure as if a `consume` operation was invoked.

## Wait For A Reply On A Temporary Queue

Using a temporary Queue to wait for a response is very simple, just configure the message being sent
and the operation will automatically wait for a response in a temporary queue:

```xml
<amqp:publish-consume
	config-ref="config"
	exchangeName="targetExchange"
	maximumWait="20"
	maximumWaitUnit="SECONDS"/>
```

In this example, the operation will `publish` a message with the current `payload` as its **body**
and the **replyTo property** of the message configured to a temporary destination, to the
`targetExchange`. Then, it will automatically try to consume the response from that temporary queue
until a message is consumed or the `maximumWait` is reached (in which case it will fail with a
`AMQP:TIMEOUT` error).

## Receive The Reply On A Known Queue

In many cases you don’t want reply queues to be created per-request basis, but instead a well-known
queue is used for replies. For this cases, all you have to do is configure the `reply-to` parameter
on the outgoing Message:

```xml
<amqp:publish-consume config-ref="config" exchangeName="targetExchange">
    <amqp:message>
    		<amqp:properties reply-to="replyToQueue" />
    </amqp:message>
</amqp:publish-consume>
```

Now the operation will `publish` a message to the `targetExchange` with the current `payload` as its
**body** and the `replyTo` **property** configured with the `replyToQueue`. Then, it will
automatically try to consume the response from the `replyToQueue` queue until a message is consumed
or the `maximumWait` is reached (in which case it will fail with a `AMQP:TIMEOUT` error).

## See Also

- [Publish Messages](https://docs.mulesoft.com/amqp-connector/latest/amqp-publish)
