The content in this documentation is for older versions of WSO2 products. For updated information on Enterprise Integration Patterns, go to the latest Micro Integrator documentation. "> The content in this documentation is for older versions of WSO2 products. For updated information on Enterprise Integration Patterns, go to the latest Micro Integrator documentation.

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 15 Next »

This section explains, through an example scenario, how the Event-Driven Consumer EIP can be implemented using WSO2 ESB. The following topics are covered:

Introduction to Event-Driven Consumer 

The Event-Driven Consumer EIP allows an application automatically consume messages as they become available. For more information, refer to http://www.eaipatterns.com/EventDrivenConsumer.html.

 

 

 

 

 

Figure 1: Event-Driven Consumer EIP 

Example scenario

This EIP is also called as an asynchronous receiver. This example scenario demonstrates how an event will be triggered based on the availability of the receiver. Related to that, a message will be consumed by the receiver.

The diagram below depicts how to simulate the example scenario using WSO2 ESB.

Figure 2: Example Scenario of the Event-Driven Consumer EIP

Before digging into implementation details, let's take a look at the relationship between the example scenario and the Event-Driven Consumer EIP by comparing their core components.

Figure 1: Event-Driven Consumer EIPFigure 2: Event-Driven Consumer Example Scenario
SenderSimple Stock Quote Client
MessageSimple Stock Quote Request
Event Driven ConsumerEvent Mediator
ReceiverTopic Subscriber, Simple Stock Quote Service

Environment setup

  1. Download an install the WSO2 ESB from http://wso2.com/products/enterprise-service-bus. For a list of prerequisites and step-by-step installation instructions, refer to Getting Started in the WSO2 ESB documentation.
  2. Start two sample Axis2 server. For instructions, refer to section ESB Samples Setup - Starting Sample Back-End Services in the WSO2 ESB documentation.
  3. Follow the steps below to create an event.
    • Start the ESB server and log into its management console UI (https://localhost:9443/carbon).
    • Select the Topics menu from the Main menu and then select the Add sub menu.
    • Enter a name for the topic. For example, EventConsumerTopic. Then click Add Topic.
    • This will create an event topic named EventConsumerTopic, and you will be directed to the Topic Browser tree view. The newly-created topic will be shown on the tree. Click on this topic and select the Subscribe option to create a static subscription. Enter the value http://localhost:9000/services/SimpleStockQuoteService in the Event Sink URL field and click Subscribe.

ESB configuration

 In the ESB's Management Console, navigate to Main menu, click Service Bus and then Source View. Next, copy and paste the following configuration, which helps you explore the example scenario, to the source view.

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://ws.apache.org/ns/synapse">
   <sequence name="fault">
      <log level="full">
         <property name="MESSAGE" value="Executing default &#34;fault&#34; sequence"/>
         <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
         <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
      </log>
      <drop/>
   </sequence>
   <sequence name="main">
      <log/>
      <event topic="EventConsumerTopic"/>
   </sequence>
</definitions>

Simulating the sample scenario

Send a request using the Stock Quote client to the ESB as follows. For information about the Stock Quote client, refer to Sample Clients section in the WSO2 ESB documentation.

ant stockquote -Dtrpurl=http://localhost:8280 -Dsymbol=Foo

After sending the request, note that a message accepting the request will show on the Stock Quote service's console. This is triggered as an event when the message is published into the topic EventConsumerTopic created earlier. All subscribers will receive the topic. 

How the implementation works

Let's investigate the elements of the ESB configuration in detail. The line numbers below are mapped with the ESB configuration illustrated in step 4 above. 

  • event [line 13 in ESB config] - Allows you to define a set of subscribers that will receive messages when the topic subscribed to receives a message. Also, see Eventing.
  • No labels