---
schema_version: "1"
id: 613403d9f22a6573883bc5f68997cf31414269671d25c624cbe09f864101f68c
title: Lifecycle of a Message Source
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/mule-sdk/latest/sources-lifecycle.md
canonical_url: https://docs.mulesoft.com/mule-sdk/latest/sources-lifecycle
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 6530baddbfc3e74d3fa8e588e89f84de802c55eae8c0cd31b9f43e7a21c1f2a0
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, lifecycle
---

# Lifecycle of a Message Source

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

Unlike operations, where the lifecycle is tied to the owning Flow, sources can be started or stopped
separately through Runtime Manager.

To support that, the `Source` class forces you to implement the `onStart()` and `onStop()` methods.

## On Start

This example from the VM connector shows the `onStart()` method:

```java
@Override
public void onStart(SourceCallback<Serializable, VMMessageAttributes> sourceCallback) throws MuleException {

}
```

In this method, you have to initialize all the resources (such as threads, schedulers, connections,
and so on) that you need so that you can produce messages. If an exception or error condition is
found trying to do that, then you have to:

- Release any resources you did got to allocate.

- Throw an exception with a meaningful message.

If the source fails to start, the app that contains it will fail to start.

> [!TIP] All of the source parameters values that defined through the `@Parameter` annotation are
> resolved and available at this point.

### SourceCallback

The method receives a SourceCallback object. The `SourceCallback` is arguably the most important
piece of the Source, since it is involved in pretty much every aspect of the source’s functionality.
We will elaborate on the uses and responsibilities of the `SourceCallback` as this documentation
progresses, but in a nutshell, the `SourceCallback` is what the source uses to communicate with the
runtime. It is used for:

- Pushing messages into the Flow

- Communicating connection issues and triggering reconnection

- Passing state between the push phase of the Source into the response handling part

Because the `SourceCallback` plays such an important role, it is very important that the provided
instance is always available. Depending on how your source’s complexity and code organization, you
may accomplish this by simply holding it as a method argument. More complex sources might need to
keep a reference to it through an instance field. If you decide to do this, then you need to make
sure that the reference is cleared when the `onStop()` method is executed

## On Stop

This method will be invoked by the runtime to make the source stop producing messages. **This method
should not fail**. Any exceptions found during the stop process should be logged and correctly
handled by the source, but after invoking this method the source must:

- Stop producing messages

- Free any allocated resources

- Be capable of being restarted

## Next step

- [Obtain configuration and connections from a Message source](https://docs.mulesoft.com/mule-sdk/latest/sources-config-connection)
