Skip to content

Instantly share code, notes, and snippets.

@djuang1
Last active November 23, 2017 10:51
Show Gist options
  • Save djuang1/1957dc0b71b89b983d85026468b9cf83 to your computer and use it in GitHub Desktop.
Save djuang1/1957dc0b71b89b983d85026468b9cf83 to your computer and use it in GitHub Desktop.
Java code to create Business Event in Mule Management Console (MMC)
package com.mulesoft.dejim;
import java.util.HashMap;
import java.util.Map;
//import org.apache.commons.logging.Log;
//import org.apache.commons.logging.LogFactory;
import org.mule.DefaultMuleEvent;
import org.mule.MessageExchangePattern;
import org.mule.api.MuleEvent;
import org.mule.api.MuleEventContext;
import org.mule.api.context.notification.ServerNotification;
import org.mule.api.lifecycle.Callable;
import com.mulesoft.mule.tracking.event.AbstractEventNotificationFiringMessageProcessor;
import com.mulesoft.mule.tracking.event.EventNotification;
public class CustomBusinessEventComponent extends AbstractEventNotificationFiringMessageProcessor implements Callable{
//private static Log logger = LogFactory.getLog(CustomBusinessEventComponent.class);
@Override
public Object onCall(MuleEventContext eventContext) throws Exception {
DefaultMuleEvent muleEvent = new DefaultMuleEvent(eventContext.getMessage(), MessageExchangePattern.REQUEST_RESPONSE, eventContext.getFlowConstruct());
// Create the ServerNotification to listen for the Business Event
final ServerNotification notification = this.createNotification(muleEvent);
// Fire off the Business Event for the Server to pick up
eventContext.getMuleContext().fireNotification(notification);
return eventContext;
}
@Override
protected EventNotification createNotification(final MuleEvent muleEvent) {
// Create KPIs (Key, Value)
Map<String, String> metaData = new HashMap<String, String>();
metaData.put("Test","Component");
return createNotification(muleEvent, "custom-event", null, metaData);
}
}
@djuang1
Copy link
Author

djuang1 commented Aug 24, 2016

Add the following line to your Mule flow to add the component:

<component class="com.mulesoft.dejim.CustomBusinessEventComponent" doc:name="Create Business Event"/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment