SAS Event Stream Processing is a powerful solution to analyze streaming data and take appropriate action instantly. When designing your ESP model, you might face some challenges regarding the test, simulation, performance analysis and workload management of your streaming application. That’s where the Event Generator comes in. An Event Generator is an ESP object that generates event streams and publishes them into an event stream processing model. The Event Generator, which is new in SAS ESP 4.1/4.2, is very useful:
Let's go into more details.
Design an Event Generator
An Event Generator is an XML string that cannot be designed in ESP Studio. Event Generators can be created, destroyed, started, and stopped through the SAS Event Stream Processing HTTP interface (REST admin API). Let’s have a look at an Event Generator complete example:
The "publish-target" tag identifies the ESP source window that we want to publish events to.
The "resources" tag defines the resources from which you can read maps, lists, and sets to be accessed from your event generation functions.
Resources can also point to external files.
The "init" section is aimed to initialize a set of values upon the start of the event generation. The resources (properties) defined above are referenced here using # symbols (e.g. #brokers, #venues).
And the "fields"tag defines the event values to be generated using a set of functions. They are based on the functions defined in Functional Window and Notification Window Support Functions in SAS Event Stream Processing: Programming Reference.
For example, the "listItem(#symbols,random(0,$numSymbols))" will return a random item from the defined list of symbols, the random function returning a number between 0 and $numSymbols.
Run an Event Generator
Once you have designed a valid Event Generator, next steps are to create it by pushing the XML into an ESP XML server and start it. Here is the command to create it. The URL means that you want to create an Event Generator called myFirstEG in the according ESP server.
Note: this example assumes you have an ESP XML Factory Server running with an admin port of 5556.
You should see the following:
If you look to the linux terminal where you started the ESP XML Factory Server (assuming you started it with the -loglevel "event.generator=trace"), you should see how the Event Generator is initialized:
Then, you are ready to start your Event Generator with the following command:
This command tells the Event Generator to load 3000 events, at a rate of 50 events per second with a blocksize of 5 events.
You should see the following:
If you look to the linux terminal where you started the ESP XML Factory Server (assuming you started it with the -loglevel "event.generator=trace"), you should see how the Event Generator publishes events:
Now it is running, you should see some events coming in your ESP model, so that you can check the consistency of your model and your rules.
You have additional REST API methods:
Finally, the real rate (number of events published per second) is defined by the maximum value of either blocksize or rate. Here are several examples to illustrate this:
Thank you for providing this good explanation how to use Event Generator functionality. I was trying to use list-url as a resource but ran into small problems.
The resource was described as follows:
<list-url name='symbols'>http://xxxxxx:8090/static/symbols.txt</list-url>
Initialization contained this line:
<value name='numSymbols'>listSize(#symbols)</value>
Symbols.txt contained these:
SAP
IBM
ORA
MSF
OMX
Now, when I run generator it creates some empty symbol values and when I used additional field to monitor the size of numSymbols it gives me 10. I guess the reason for that is function listSize cannot be applied to resource type url-list? Any suggestions how I could solve this to get random elements from Symbols.txt file?
Thank you.
Rain
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.