Unknown macro: {next_previous_links}
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 14 Next »

In addition to the default receiver types, you can define your own custom receiver, which gives more flexibility to receive events that are sent to WSO2 products. Since each event receiver implementation is an OSGI bundle, you can deploy/undeploy it easily on the WSO2 product. To create a custom event receiver, import org.wso2.carbon.event.input.adaptor.core package with the provided skeleton classes/interfaces required by a custom receiver implementation.

Implementing InputEventAdapter Interface

org.wso2.carbon.event.input.adapter.core.InputEventAdapter interface contains the event receiver logic that will be used to receive events. You should override the below methods when implementing your own custom receiver.

  1. void init(InputEventAdapterListener eventAdaptorListener) throws InputEventAdapterException

    This method is called when initiating event receiver bundle. Relevant code segments which are needed when loading OSGI bundle can be included in this method.

  2. void testConnect() throws TestConnectionNotSupportedException, InputEventAdapterRuntimeException, ConnectionUnavailableException

    This method checks whether the receiving server is available.

  3. void connect() throws InputEventAdapterRuntimeException, ConnectionUnavailableException

    Method connect() will be called after calling the init() method. Intention is to connect to a receiving end and if it is not available "ConnectionUnavailableException" will be thrown.

  4. void disconnect()

     disconnect() method can be called when it is needed to disconnect from the connected receiving server.

  5. void destroy()

    The method can be called when removing an event receiver. The cleanups that has to be done when removing the receiver can be done over here.

  6. boolean isEventDuplicatedInCluster() (To be edited)

    Returns a boolean output stating whether an event is duplicated in a cluster or not.

  7. boolean isPolling() (To be edited)

    Checks whether events get accumulated at the adapter and clients connect to it to collect events.

Implementing InputEventAdapterFactory Class

org.wso2.carbon.event.input.adapter.core. InputEventAdapterFactory class can be used as the factory to create your appropriate event receiver type. You should override the below methods when extending your own custom receiver.

  1. public String getType()

    This method returns the receiver type as a String.

  2. public List<String> getSupportedMessageFormats()

    Specify supported message formats for the created receiver type.

  3. public List<Property> getPropertyList()

    Here the properties have to be defined for the receiver. When defining properties you can implement to configure property values from the management console.

  4. public String getUsageTips()

    Specify any hints to be displayed in the management console.

  5. public InputEventAdapter createEventAdapter(InputEventAdapterConfiguration eventAdapterConfiguration, Map<String, String> globalProperties)

    This method creates the receiver by specifying event adapter configuration and global properties which are common to every adapter type.

Exposing Custom Event Receiver as an OSGI Service

Apart from above, you can maintain a service class under internal\ds\ directory to expose the custom event receiver implementation as an OSGI service. When exposing the service, it needs to expose as “InputEventAdaptorFactory” type. Below is a sample implementation for a service class for a custom defined receiver:

/**
 * @scr.component name="input.CustomReceiverService.component" immediate="true"
 */
 
public class CustomReceiverServiceDS {
 
    private static final Log log = LogFactory.getLog(CustomReceiverServiceDS.class);
 
    protected void activate(ComponentContext context) {
 
        try {
            InputEventAdaptorFactory customInputEventAdaptorFactory = new CustomInputEventAdaptorFactory();
            context.getBundleContext().registerService(InputEventAdaptorFactory.class.getName(), customInputEventAdaptorFactory, null);
            log.info("Successfully deployed the Custom Event Receiver Service");
        } catch (RuntimeException e) {
            log.error("Can not create the Custom Event Receiver Service ", e);
        }
    }
}


Furthermore you can have a utility directory as internel\util\ where you can place utility classes required for the custom receiver implementation.

Deploying Custom Event Receiver

Deploying a custom event receiver is very simple in WSO2 CEP 4.0.0. Simply implement the custom event receiver type, build the project and copy the created OSGI bundle that is inside the "target" folder into the <CEP_HOME>/repository/components/dropins. In CEP server startup, you can see the newly created event receiver type service in the server startup logs. The newly created custom event receiver type will also be visible in the UI with necessary properties. Now you can create several instances of this event receiver type.

  • No labels