Stream Explorer and JMS for both inbound and outbound interaction image56

Stream Explorer and JMS for both inbound and outbound interaction

In this article, we will look at the very common interaction between Stream Explorer and JMS. JMS is a commonly used channel for decoupled exchange of messages or events. Stream Explorer can both consume messages from a JMS destination (through Stream) and publish findings to a JMS destination (with a target). The use case we discuss here is about temperature sensors: small devices distributed over a building, measuring the local room temperature every few seconds and reporting it over JMS. The Stream Explorer application has to look out for rooms with quickly increasing temperatures and report those over a second JMS queue. Note: this article describes the Java (SE) code used for generating temperature signals. This class generates temperature values (in Celsius!) for a number of rooms, and publishes these to the queue temperatureMeasurements. At some random point, the class will start a fire in a randomly selected room. In this room, temperatures will soon be over 100 degrees. Also in this article is Java class HotRoomAlertProcessor  that consumes messages from a second JMS Queue. Any message received on that queue is reported to the console.

Our objective in this article is to read the temperature measurements from the JMS Queue into a Stream Explorer application, calculate the average value per room and then detect the room on fire. This hot room should then be reported to the JMS Queue.

Open Stream Explorer and from the Stream Explorer Catalog page, create a new item of type Stream. Select JMS as the source type.

image

Press Next.

Configure the URL for the WebLogic domain (http://localhost:7101), the WebLogic Admin’s username and password (weblogic/weblogic1) and the JNDI Name for the JMS Queue (or Topic): jndi/ temperatureMeasurements

image

Press Next.

Define a new Shape. The properties in the JMS (Map)Message produced by the Java Class TemperatureSensorSignalPublisher are called RoomId (of type String) and Temperature (of type Float).
image

Press Create.

The Exploration editor appears to create an exploration based on the Stream.

Define a Name. Then click on Create.

image

The temperature measurement events start streaming in:

image

The first step is the definition of a Summary: calculate the average temperature per room. Also set the time range for the aggregation to 10 seconds (determine the temperature using the most recent 10 seconds worth of data) and the evaluation frequency to 5 seconds.

image

Fewer events are shown in the Live Output Stream – and with less variation.

Next, add a filter: we are going to hunt for the room on fire. Only records with an average temperature higher than 80 degrees should be reported. Also change the name of the property AVG_of_Temperature to AverageTemperature.

image

The screenshot shows that in this case, it is the Cafeteria where there is a fire. If you stop class TemperatureSensorSignalPublisher and then start it again, it will take some time for it to start a fire again and when the fire was started, the Live Output Stream will show it.

Finally, click on Configure Target.

Configure a JMS Target, as shown in the figure. The URL is the familiar one (t3://localhost:7101), username and password are weblogic and weblogic1 and the JNDI Name of the JMS target is jndi/hotRooms.
image

Click on Finish. Publish the Exploration.

When there is now a room discovered with temperatures in the hot zone, a message will be published to the JMS Queue, in the form of a MapMessage with properties RoomId and AverageTemperature.

Stop and start class TemperatureSensorSignalPublisher. Run class HotRoomAlertProcessor to have it start listening to the jndi/hotRooms queue.

The former writes:

image

And the latter will report hot rooms by writing a message to the console:

image

While the Stream Explorer browser interface shows:

image