Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This section explains, through an example scenario, how the Event-Driven Consumer EIP can be implemented using WSO2 ESBthe ESB Profile of WSO2 Enterprise Integrator (WSO2 EI). The following topics are covered:

Table of Contents

...

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

 

 

 

 

 






Figure 1: Event-Driven Consumer EIP 

...

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

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.

Event-Driven Consumer EIP (Figure 1)Event-Driven Consumer Example Scenario (Figure 2)
SenderSimple Stock Quote Client
MessageSimple Stock Quote Request
Event Driven ConsumerEvent Mediator
Receiver
Topic Subscriber,
Simple Stock Quote Service

Environment setup

  1. Download and install
  2. WSO2 ESB from http://wso2.com/products/enterprise-service-bus
  3. the ESB Profile of WSO2 Enterprise Integrator (EI). For a list of prerequisites and step-by-step installation instructions,
  4. refer to Installation Guide in the WSO2 ESB documentation
  5. go to Installing the Product in WSO2 EI Documentation.
  6. Start
  7. two sample
  8. an instance of Sample Axis2 server. For instructions,
  9. refer to the section Setting Up the ESB Samples -
  10. go to Starting the Axis2 server in
  11. the
  12. WSO2
  13. ESB documentation
  14. EI Documentation.
  15. Follow the steps below to create an event.
    • Start the ESB
  16. server
    • Profile 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 EventConsumerTopic as the name
  17. for
    • of the topic, and then click Add Topic.
    • Click
  18. the newly created topic
    • EventConsumerTopic in the topic browser tree, and then click Subscribe 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 On the ESB's Management Console of the ESB Profilenavigate to the Main menu and click Source View in the Service Bus section . Next, copy and paste the following configuration , which helps you to the source view. Then you can explore the example scenario, to the source view. 

Anchor
step4
step4

Code Block
languagehtml/xml
linenumberstrue
<?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

  1. Send a request using the Stock Quote client to the ESB as follows

...

  1. :

    Code Block
    ant stockquote -Dtrpurl=http://localhost:8280 -Dsymbol=foo

    For information on the Stock Quote Client and its operation modes, see Stock Quote Client in the WSO2 EI Documentation.

  2. After sending the request, note that a message accepting the request

...

  1. is displayed on the Stock Quote service's console. This is triggered as an event when the message is published into the topic EventConsumerTopicthat you 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 shown provided above.

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