Loading an existing message flow into memory

Use the IBM Integration API when developing message flow applications to load a message flow into memory. You can then access the message flow in your Java™ code.

You must load a message flow into memory to use it with the IBM Integration API methods within your Java code. To load a message flow into memory, create a File object and use the read() method of the FlowRendererMSGFLOW, which makes the message flow available for your Java code. The read() method takes the message flow project that contains the required message flow file and the relative path to the message flow file from this project.

The following example shows how to load a message flow that is in the mqsi directory:

import java.io.File;
import java.io.IOException;
import com.ibm.broker.MessageBrokerAPIException;
import com.ibm.broker.config.appdev.MessageFlow;
import com.ibm.broker.config.appdev.FlowRendererMSGFLOW;

public class LoadMessageFlow {
    public static void main(String[] args) {
        File msgFlow = new File("../mqsi/main.msgflow");
        try {
            MessageFlow mf1 = FlowRendererMSGFLOW.read(msgFlow);
        } catch (IOException e) {
            // Add your own code here
            e.printStackTrace();
        } catch (MessageBrokerAPIException e) {
            // Add your own code here
            e.printStackTrace();
        }
    }
}	

Pattern authoring

When you create patterns with the pattern authoring tool, use the getMessageFlow() method of the PatternInstanceManager object, which is automatically passed to your Java code. Modify a pattern instance to load a message flow into memory and make it available to other IBM Integration API methods.

The following example shows how to load a message flow that is in the default schema:
public class MyJava implements GeneratePatternInstanceTransform {
    public void onGeneratePatternInstance(PatternInstanceManager patternInstanceManager) {
        MessageFlow mf1 = patternInstanceManager.getMessageFlow("MyFlowProject", "main.msgflow");
        if (mf1 != null) {
           // Message flow was found
        }
        else {
           // Message flow was not found
        }
    }
}
The following example shows how to load a message flow that is in the mqsi schema:
public class MyJava implements GeneratePatternInstanceTransform {
    public void onGeneratePatternInstance(PatternInstanceManager patternInstanceManager) {
        MessageFlow mf1 = patternInstanceManager.getMessageFlow("MyFlowProject", "mqsi/main.msgflow");
        if (mf1 != null) {
           // Message flow was found
        }
        else {
           // Message flow was not found
        }
    }
}