WSO2 Complex Event Processor is succeeded by WSO2 Stream Processor. To view the latest documentation for WSO2 SP, see WSO2 Stream Processor Documentation.
||
Skip to end of metadata
Go to start of metadata

Introduction

This sample demonstrates how to run WSO2 CEP in High Availability (HA) mode. This uses the following window query to demonstrate how a processing continues even after one server shuts down.

from pizzaOrder#window.length(20)
select count(orderNo) as totalOrders, sum(price) as sumPrice
insert into orderCount;

Above query calculates the order count and the sum of the prices of the last 20 orders.

Prerequisites

Follow the steps below to set up the prerequisites for this sample.

This sample uses two WSO2 CEP nodes. (Node1 as the active node and Node2 as the passive node.)

  1. Set up the prerequisites required for all samples.
  2. Set up the two nodes (ignore the presenter node and backup node configurations for this sample) as mentioned in the configuring High Availability in CEP nodes sectionSummarised steps are as follows.

    1. Set the value of the <Offset> element of the <CEP_HOME>/repository/conf/carbon.xml file as shown below in Node2to start it with a port offset of 1. 

    2. In the <CEP_HOME>/repository/conf/axis2/axis2.xml file, enable clustering in wka mode on both nodes.

    3. In the <CEP_HOME>/repository/conf/event-processor.xml file, enable HA mode and configure both nodes to have separate <eventSync/> and <management/> host and port configs.

    4. Share the registry by adding the Node1's H2 database as the Node2's database.

Building the sample

Start both WSO2 CEP nodes with the sample configuration numbered 0503. For instructions, see Starting sample CEP configurations

This sample configuration creates the following.

  • Two streams with the IDs org.wso2.sample.pizza.orderStream:1.0.0 and org.wso2.sample.order.count:1.0.0
  • An event receiver named pizzaOrderReceiver
  • An event publisher named pizzaCountPublisher
  • An execution plan named PizzaOrdersExecutionPlan

Executing the sample

Follow the steps below to execute the sample.

  1. Navigate to the <CEP_HOME>/samples/cep/producers/http/ directory of any node, and execute the following Ant command using another tab in the CLI: 

    ant -Durl=http://localhost:9763/endpoints/pizzaOrderReceiver -Dsn=0503

    This builds the HTTP client and publishes the events defined in the <CEP_HOME>/samples/cep/artifacts/0503/pizzaOrderReceiver.txt file to the pizzaOrderReceiver endpoint in Node1.

    You view Node 1 (active node) receiving the output events in the logs of it in the CLI as shown below.

    published events received by Node 1

     

    Value of totalOrders is incremented by one for each new event, and the sum of the prices is increased by the frequency of each event.

  2. Repeat step 1 using the following Ant command: ant -Durl=http://localhost:9764/endpoints/pizzaOrderReceiver  -Dsn=0503

    This builds the HTTP client and publishes the events defined in the <CEP_HOME>/samples/cep/artifacts/0503/pizzaOrderReceiver.txt file to the pizzaOrderReceiver endpoint in Node2.

    You view Node1 (active node) receiving the output events in the logs of it in the CLI as shown below.

    events published to Node2

    Even if events are sent to one server, the two nodes coordinate in a way so that both receive all the events. Only the active node publishes the output events.

  3.  Shutdown the active node (Node1). Now, Node2 becomes the active node.
  4. Repeat step 2 and use the command to send events to the running node.

    You view the running node receiving the output events in the logs of it in the CLI as shown below.

    Even though one node is down, the other carries on processing the events.

  • No labels