Reading Time: 3 minutes
Note that this approach is no longer recommended if you are using Mule 3.0.0 or later. Instead you can use the ObjectStore. This allows use to store objects in memory, in a persistent store or across Mule HA clusters automatically. You can learn more about Mule 3.0 here and download it here.

Recently, there was a great question on one of the Mule mailing lists about where to store runtime that can be used across the app. If you need to store runtime data that is available across your Mule application, you can store the data as objects in the Mule Registry. You can get a handle to the Registry from anywhere that you have access to the MuleContext, as in most Mule entities. For example, you could store the object as follows:

muleContext.getRegistry().registerObject(<span class="code-quote">"foo"</span>, new MyFoo());

You could then update the object from somewhere else:

Foo foo = (Foo) muleContext.getRegistry().lookupObject(<span class="code-quote">"foo"</span>);
// Replace the previous object
muleContext.getRegistry().registerObject(<span class="code-quote">"foo"</span>, foo);
latest report
Learn why we are the Leaders in API management and

This approach is useful for storing objects such as routers that are needed by multiple components across your application.

I’ve added this info to the Mule User Guide for easy reference in the future. Thanks to Travis and Andrew for the info.