---
schema_version: "1"
id: 3b31b22689c25e7e249e1fa219818881e4601136b0ef627a31c081a7f8c18d26
title: Sending Asynchronous Responses from a Message Source
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/mule-sdk/latest/sources-async-response.md
canonical_url: https://docs.mulesoft.com/mule-sdk/latest/sources-async-response
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 106489f6a7ad240dbb1a4cfdfcc2c8c1508b07dd3c3c0a77cb83ee33aa1fa01b
description: MuleSoft Documentation Site
release: "1.13"
latest: true
---
---
product: Mule SDK
version: 1.13
is-latest-version: true
keywords: mule, sdk, sources, listener, triggers, response, output, asynchronous
---

# Sending Asynchronous Responses from a Message Source

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

Sources can send responses in an asynchronous way. Some of the main uses cases for asynchronous
sources are:

- The response operation is non-blocking.

- The response operation is blocking, but it is asynchronously executed in a thread other than the
  one that initiates it (most typically, the thread executing a method annotated with `OnSuccess` or
  `OnError`).

- The source will perform asynchronous auditing for which it needs to consume a response stream in a
  separate thread.

In these cases:

- The runtime needs to know that the response will be asynchronous. Otherwise, there will be a race
  condition between the thread emitting the response and the runtime that is trying to free up
  resources associated with the message that is getting a response.

- Methods annotated with `OnSuccess` or `OnError` must have an argument of type
  `SourceCompletionCallback`. That is enough to signal the runtime that the source is asynchronous.

The runtime will not finish the associated event until either the `success()` or `error(Throwable)`
methods are invoked. Note that this is a very strong contract. A source that requests a
`SourceCompletionCallback` without properly notifying the runtime is one likely to freeze the entire
runtime eventually.

Here is an example:

```java
@OnSuccess
public void onSuccess(@Content String response, SourceCompletionCallback callback) {
  asyncResponder.sendResponse(response, new ResponderCallback() {
    void onSuccess() {
      callback.success();
    }

    void onFailure(Throwable t) {
      callback.error(t);
    }
  };)
}
```

## Next Step

[Transactional Message Sources](https://docs.mulesoft.com/mule-sdk/latest/sources-transactions)
