Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save paulcalabro/751077bc1d6d5dbf186c7f4fb37230d6 to your computer and use it in GitHub Desktop.
Save paulcalabro/751077bc1d6d5dbf186c7f4fb37230d6 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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment