Friday, February 15, 2013

Accessing registry resources from class mediator in wso2esb

In the mediation process, users might need to access the registry resources, which are stored in the governance/config registries in wso2esb.
In the normal sequence flow, we could point the resources as registry keys in the mediators. But if we want to access them in a class mediator, where we may need to do custom process on the resource, we could retrieve the "WSO2Registry" instance from the  "SynapseConfiguration" and from the registry instance we could access different resources which are stored in the different registries.

Likewise if we have a 'LocalEntry' defined in the synapse configuration we could retrieve it from the "LocalRegistry". LocalEntries  are elements, used to declare registry entries that are local to the ESB instance. They are static resources and has high priority than a resource with the same name  hosted in embedded wso2registry.

Here is a sample class mediator, which can be used to retrieve a LocalEntry and resources hosted in governance/config registry.
import org.apache.synapse.MessageContext;
import org.apache.synapse.config.Entry;
import org.apache.synapse.mediators.AbstractMediator;
import org.apache.synapse.registry.Registry;
public class CustomRegistryRetriveMediator extends AbstractMediator {
    public boolean mediate(MessageContext synapseMsgContext) {

        // if localentry "
testLocalentry" defined in synapse econfig
        Entry localEntryObj = (Entry) synapseMsgContext.getConfiguration()
        System.out.println(" value: " + localEntryObj.getValue());
        System.out.println(" Filename : " + localEntryObj.getFileName());

        // goverance/config registry
        Registry regInstance = synapseMsgContext.getConfiguration()
        Object obj=regInstance.getResource(new Entry("gov:/test1.txt"),null);       
        Object obj2=regInstance.getResource(new Entry("conf:/test2.txt"),null);   
        return true;


  1. Hi. Thanks for writing this up. Can you please share a POM file one can use to build this mediator for API Manager 1.3.1?

  2. Check this post[1] fro sample pom.. Consider the available version of the synapse


  3. What are the differences between local entry and registry? Can we share local entries within the clustered ESBs? Where is the local entries real location, are they save in memory or they are in HDD and for any invocation ESB loads them from HDD to RAM, I ask it for performance issues.

  4. Local entries will be saved in the filesystem. You can see your local entries in the synapse-config folder/local entries directory.
    You can not share, since it is local to that server node. If you want to share the configuration among cluster nodes , you have to safe them in registry.(ie: config registry) All cluster nodes will point to the same config registry, so the configurations can be shared.

  5. Or else, to share same configurations , you can use deployment synchronizer. It is SVN based. So, one node will be committing to a central location and other nodes will take checkout from there.

  6. Thanks, useful and complete.