WSO2 Governance Registry generates events for each significant registry operation. Through the Management Console and through APIs, you can create subscriptions to these events. WSO2 Governance Registry can publish notifications to external or internal endpoints. On the other hand, WSO2 Governance Registry contains an Apache Axis2 based runtime as a part of the WSO2 Carbon Framework. You can deploy web services on this runtime, which can be used as internal endpoints to receive notifications generated on the WSO2 Governance Registry. A Message Receiver is an extension mechanism of Apache Axis2 which allows service authors to define how message processing should happen within a service endpoint. Using a message receiver you can implement an endpoint without physically requiring an implementation class for your service. This makes it much easier for us to very easily develop event subscribers.
This sample explains how to:
- Create a message receiver to subscribe to notifications on WSO2 Governance Registry
- Forward notifications from WSO2 Governance Registry to WSO2 Business Activity Monitor.
Once successfully deployed this sample will forward notification generated on WSO2 Governance Registry to the WSO2 Business Activity Monitor. We will be reusing the code of the Handler Sample in this example. This sample requires Apache Maven and WSO2 Business Activity Monitor. See System Requirements for links on how to install it. Also see Installing WSO2 Business Activity Monitor on Linux from Binary Distribution.
1. Open to
repository/conf/carbon.xml and set the port offset to 1.
2. Start the WSO2 Business Activity Monitor. See Installing WSO2 Business Activity Monitor on Linux from Binary Distribution
3. Deploy the KPI_Registry_Activity.tbox BAM Toolbox to WSO2 Business Activity Monitor.
A BAM Toolbox is an installable archive which contains stream definitions, dashboard components and analytics for WSO2 Business Activity Monitor. The KPI_Registry_Activity.tbox is a pre-built BAM Toolbox based on the KPI Monitoring Sample example of WSO2 Business Activity Monitor, which is specifically designed for this sample. Read the KPI Monitoring Sample example of WSO2 Business Activity Monitor to learn how to make changes to this BAM Toolbox or create your own.
ToolBox From File System option and fill in the URL of the KPI_Registry_Activity.tbox Toolbox. Then click on the
If the BAM Toolbox fails to install from the URL download the KPI_Registry_Activity.tbox Toolbox to your local file system and upload it.
4. Navigate to
samples/handler/src to find the source code of the Handler Sample.
5. Add the following dependencies to your POM file:
Project Object Model (POM) is an XML representation of a Maven project held in a file named pom.xml. You should find POM file by the name pom.xml inside
6. Comment-out the following in your POM file:
The Fragment-Host Bundle Manifest Header declares this sample bundle to be a Fragment of the Registry Kernel. This would mean that the sample handler bundle will become an extension to the Registry Kernel. However, bundles containing
services.xml files would not be deployed until the Apache Axis2 runtime has been initialized. Due to OSGi bundle start-up order, it is required that the Registry Kernel starts up before the Apache Axis2 runtime.
Since the Fragment now also being an extension to the Registry Kernel, the combination of this bundle and the Registry Kernel (plus any other fragments) should start up before the Apache Axis2 runtime. But, due to the bundle not getting deployed until the Apache Axis2 runtime has been initialized, it will create a deadlock situation. Due to this reason, we have to get rid of the Fragment-Host header.
7. Add the following content to a file named
8. Add a new Java Class named
GREG_HOME/samples/handler/src/src/main/java/org/wso2/carbon/registry/samples/receiver/SampleMessageReceiver.java with the following source:
9. Compile the source code by running the following command inside
mvn clean install will trigger an Apache Maven Build in your command line. This requires you having installed Apache Maven. See System Requirements for links on how to install it.
A successful run of Apache Maven will generate a report similar to the following:
10. Copy the <
org.wso2.carbon.registry.samples.handler-5.4.0.jar file into the <
11. Start the server and observe the command prompt. See Running the Product for more information.
You should also observe a log similar to the following explaining that your Message Receiver was successfully deployed.
12. After the server has started, log into the Management Console and add a notification to the root collection with the following settings:
- Event - Update
- Notification - SOAP
- Endpoint -
- Hierarchical Subscription Method - Collection, Children and Grand Children
13. Now perform various operations on the registry such such Adding/Updating Resources, Setting Properties etc. This should generate notifications which will then be forwarded for BAM. You should see lines similar to the following printed on your command prompt, which indicates that you events were successfully generated. For best results, create multiple user accounts and log in using different credentials while you perform operations.
14. Navigate to the Gadget Portal of WSO2 Business Activity Monitor to see the statistics corresponding to your operations.
A Message Receiver must implement the
org.apache.axis2.engine.MessageReceiver interface. Read more about Message Receivers to get a better understanding of their uses.