Storing Objects in the Registry
|Mule Runtime Engine versions 3.5, 3.6, and 3.7 reached End of Life on or before January 25, 2020. For more information, contact your Customer Success Manager to determine how you can migrate to the latest Mule version.|
If you need to store runtime data that is available across the application, you can store the data as objects in the Registry. You can get a handle to the Registry from anywhere that you have access to the MuleContext, as in most Mule ESB entities. For example, you could store the object as follows:
muleContext.getRegistry().registerObject("foo", new MyFoo());
You could then update the object from somewhere else:
Foo foo = (Foo) muleContext.getRegistry().lookupObject("foo"); foo.setBarVal(25); // Replace the previous object muleContext.getRegistry().registerObject("foo", foo);
This approach is useful for storing an object that is needed by multiple components across your application.