Creating a custom event handler for event notification
The event handler publishes the event message to the external system. Use this procedure to create a custom event handler.
About this task
The steps to create an event handler are similar to the steps used to create other types of handlers. All handlers are created in InfoSphere® MDM Workbench.
Procedure
Create the custom handler:
- In InfoSphere MDM Workbench, open your project configuration .imm file.
- From the MDM Configuration perspective, select Handlers and
click Add.
- Type a unique name for your Handler Name.
- Use the default Sequence Number provided.
- Select All for Callback Type and Interaction Code.
- Enter any Arguments for the handler.
Arguments are generally in the format of
key=value. Separate multiple arguments with a carat (^) character.
- Select the handler that you just created and click Generate to
start the Create a Master Data Management Handler Class wizard.
- Specify or browse to a Handler bundle project name.
- Select Add bundle to composite and specify the Composite project .cba file, then click Next to load the Handler Information window.
- Enter the appropriate information for the handler:
- Select the Type of interaction from the dropdown menu.
- Enter or browse to the Name of the handler.
- Enter or browse to the Java class for the handler.
- Enter the Java package name for the handler.
- Click Finish. There are now two projects in the Navigator view: ConfigurationProjectName.cba and ConfigurationProjectName.handlers.
Implement the com.initiatesystems.hub.event.handler.IEventHandler interface:
- In the Navigator view, go to ConfigurationProjectName.handlers/ejbModule/handlers/event/and open the CustomerEventHandlerName.java file and configure the parameters.
- Change the package name in the import property from:
com.initiatesystems.hub.event.handler.IEventHandlertocom.initiatesystems.hub.event.handler.yourhandler_name.For example, the default JMS handler uses the package name ofcom.initiatesystems.hub.event.handler.jms. - The following is is the
IEventHandlerinterface that you must implement for your custom handler:{ public static final int EVENT_PUBLISH_SUCCESS = 0; public static final int EVENT_PUBLISH_ERROR_RECOVERABLE = 1; public static final int EVENT_PUBLISH_ERROR_UNRECOVERABLE = 2; public void init() { } public void addDestination(String destName, String destArgs) { } public int publish(String destName, String msg) { } public void shutdown() { } } - void init(): This method is called when the event handler is loaded by the OSGi framework. If your destination or queue requires any initialization work, add the code between the braces { }.
- void addDestination: This method
is called by the event manager to notify the event handler of the
destinations that are being assigned to this Handler. This method
can be called multiple times (because multiple destinations can be
configured and be assigned to the same event handler). In addition, every time a new destination is added or updated in InfoSphere MDM Workbench, this method is called so that the event handler can update the destination in its internal cache. The method has two arguments:
- destName: Unique destination name per handler
- destArgs: The arguments that are configured in step 2.d
- int publish: This method is called
by the event manager. The arguments are as follows:
- destName: Destination to which this message must be published
- msg: Actual XML message as a string
Note: When you first open the *.java file, the publish method shows as:public boolean publish (String destName, String msg). For event handlers, make sure that you replace that line with: public int publish(String destName, String msg) - Provide the integer for the return type. Values are:
- IEventHandler.EVENT_PUBLISH_SUCCESS = 0: if the message is received successfully by the destination
- IEventHandler.EVENT_PUBLISH_ERROR_RECOVERABLE = 1: if the message is not received successfully and you want to attempt to resend the message according to the event manager recoverable error logic
- IEventHandler.EVENT_PUBLISH_ERROR_UNRECOVERABLE = 2: if the message is not received successfully and the message must be handled according to the event manager unrecoverable error logic
- shutdown(): This method is called when the event manager shuts down. You can add any cleanup work that you want the handler to do here. If you have open connections to something (such as a JMS queue), then you might want to close the open connections.
Configure your blueprint.xml:
- In the Navigator view, go to ConfigurationProjectName.handlers/BundleContent/OSGI-INF/blueprint and open the event-handlers.xml file.
- Set the interface property as:
<service interface="com.initiatesystems.hub.event.handler.IEventHandler"> - Set the handler name value to the same name as you entered
in step 2.a. For example:
<entry key="handlerName" value="XYZCustomHandlerName"/> - Save and close the file.
- Deploy the CBA to the operational server.