State Machine for Async Service - learn-tibco-cep/tutorials GitHub Wiki
In this tutorial, we implement an asynchronous service by using a State Machine for the service handler. Upon receipt of a client request, this service collects multiple responses from other data services, and then assembles and asynchronously returns a client response by using a FTL message endpoint.
Key Concepts and Implementation Tips
Besides the fact that asynchronous service is a common CEP application pattern, the implementation of this tutorial introduces the following concepts and practical tips that can be applied to other BE applications.
- State Machine is a UML diagram that specifies state transitions of a service handler object. At runtime, the state machine controls the flow of rule executions triggered by inbound messages or timeout events.
- FTL Channel Destinations specify FTL message endpoints used to communicate with clients and other service providers. This tutorial will cover common practices about using the FTL
pubsub
andshared
endpoints. - Global Variables are used to define configurable application parameters and their default values. This tutorial configures these variables by using properties in the CDD file.
- Scorecards specify singleton data structures. This tutorial uses a Scorecard to store a set of constants.
- Performance Metrics of a runtime BE engine can be collected by a few different approaches. This tutorial provides a utility for collecting detailed application stats by using BE rule-functions.
- Concurrent Map is a thread-safe Map data structure that can be updated concurrently by multiple threads. This tutorial uses Concurrent Maps as a thread-safe in-memory store for performance metrics.
- Test Driver is often used to simulate client activities in performance testing. This tutorial demonstrates how such test drivers can be configured as a separate PU in the same BE application project.
- Mock Service is often used to simulate external services in system functional testing. This tutorial demonstrates how a mock service can be easily configured as a separate PU in the same BE application project.
Prerequisites
This tutorial will not describe the details about how to create individual artifacts from scratch. Beginner BE developer may refer to the previous tutorial, Get Started, to learn about the steps for creating key BE artifacts in BE studio.
Service Components
This tutorial implements 3 processing agents that interact with each other via FTL endpoints as shown in the following figure.
The Async Service
agent is the main application component. The design and implementation of a BE application typically involves artifacts of Events
, Concepts
, Rules and Rule-functions
, and Channels
. The following linked pages explains the artifacts of Async Service
agent in more detail.
Mock Service
This tutorial includes a Mock Service
that simulates a data service that returns multiple data responses for each received service request. The implementation of the Mock Service
is simply a preprocessor function onServiceRequest in the project folder TestMock
. The function adds a random delay to each response message to simulate real-world service performances.
The Mock Service
also provides artifacts to simulate delayed batch processes. The delayed batch process uses the same dispatching technique that are described in more detail in the following section for Test Driver
. The batch process, however, is not used by this Async Service
, and thus it is disabled by setting the variable Mock/BufferSize = 0
.
Test Driver
The linked page Test Driver describes a multi-threaded client simulator included as part of the tutorial. It is used for end-to-end performance testing, and it also demonstrates a few practical implementation tips that can be applied to other BE applications.
Ignite Cache and Performance Test
A CDD file DemoCache.cdd is configured to test the performance of this application with Apache Ignite cache. The linked page Ignite Cache describes the configuration and test results.
Practical Tips
In each of the above linked pages, a list of BE implementation tips are explained to help readers to understand the design of the corresponding application component. These tips will help BE application developers to design and implement cleaner and more efficient applications.
Source Code
The complete BE project described in this tutorial can be downloaded from AsyncService. The Project README also explains how to start all the components and collect performance stats.
You may clone the AsyncService
repository, and import it into your BE studio workspace as a Existing TIBCO BE Studio Project
.
Next Step: Data Persistence