WSO2 CEP - Publish Events Using Java Client

WSO2 CEP - Publish Events Using Java Client

The last article: WSO2 CEP - Hello World!, explained how to set up WSO2 CEP with a simple event processor. This article shows you the way to send events to the CEP using a Java client. Actually it is nothing more than an HTTP client which can send the event to the CEP through HTTP request.

Step 0:
Follow the previous article and setup the CEP engine. This article uses the same event processor and receiver defined in the previous article to test the Java client.

Step 1:
Create a new simple Maven project in Eclipse.

Step 2:
Give the Group Id: "com.javahelps" and Artifact Id: "cepclient" and click on the "Finish" button.
Read More
Prototype Design Pattern

Prototype Design Pattern

Name: Prototype Design Pattern

Type: Creational Design Pattern

Purpose:
  • Improving performance by cloning objects.
  • Minimize complexity in object creation.

Sample Problem and Solution:
Consider a problem where you need a 64x64 grid Board class to represent a chess board. A possible design is provided here.
public class Cell {
    private String color;

    public Cell(String color) {
        this.color = color;

        // Make it time consuming task.
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
        }
    }

    public String getColor() {
        return color;
    }

    @Override
    public String toString() {
        return color.substring(0, 1);
    }
}
In this code, Thread.sleep is used to make the object creation as a time consuming operation.
public class Board {
    public static final int NO_OF_ROWS = 8;
    public static final int NO_OF_COLUMNS = 8;

    private final Cell[][] board;

    public Board() {
        this.board = new Cell[NO_OF_ROWS][NO_OF_COLUMNS];

        for (int row = NO_OF_ROWS - 1; row >= 0; row--) {
            for (int col = NO_OF_COLUMNS - 1; col >= 0; col--) {
                if ((row + col) % 2 == 0) {
                    board[row][col] = new Cell("WHITE");
                } else {
                    board[row][col] = new Cell("BLACK");
                }
            }
        }
    }

    public void print() {
        for (int row = 0; row < NO_OF_ROWS; row++) {
            for (int col = 0; col < NO_OF_COLUMNS; col++) {
                System.out.print(board[row][col] + " ");
            }
            System.out.println();
        }
    }
}
public class Main {

    public static void main(String[] args) {
        // Get the start time
        long startTime = System.currentTimeMillis();

        Board chessBoard = new Board();

        // Get the end time
        long endTime = System.currentTimeMillis();

        System.out.println("Time taken to create a board: " + (endTime - startTime) + " millis");

        // Print the board
        chessBoard.print();
    }

}

Read More

WSO2 CEP - Hello World!

WSO2 Siddhi CEP is a lightweight, easy-to-use open source Complex Event Processing Engine (CEP) under Apache Software License v2.0. Siddhi CEP processes events which are triggered by various event sources and notifies appropriate complex events according to the user specified queries.
This article helps you to process a simple event using WSO2 CEP where events are sent through HTTP connection and the output is printed in Terminal.

Prerequisite:
Oracle JDK 1.6 or latest
Memory – Minimum 2GB
Disk – Minimum 1 GB
For more details: Installation Prerequisites

Step 1:
Download and extract the latest version of WSO2 CEP from the official link: WSO2 Complex Event Processor

Step 2:
Install Postman in Google chrome. We will use Postman to send HTTP requests to the CEP. You can use any other HTTP clients for this purpose.

Step 3:
Open your terminal in wso2cep-x.x.x folder and execute the following command.
Linux users:
./bin/wso2server.sh

Windows users:
.\bin\wso2server.bat

Step 4:
Visit to the "Mgt Console URL" which is printed in the Terminal. In my computer this URL is: https://10.111.15.43:9443/carbon/ but it may vary depending on the system.

Step 5:
Login to the dashboard using username: admin and password: admin.

Step 6:
Go to the Streams tab and click on “Add Event Stream” link.

WSO2 CEP - Hello World!

Read More

Contact Form

Name

Email *

Message *