While working with EMS based messaging in TIBCO, you may come across scenarios where you want to select some specific kind of messages only from a queue or a topic and process that instead of getting all the messages from that destination. JMS provides Message Selector feature which comes into play in this type of scenarios.
In this step by step tutorial, you will learn how to use message selector in TIBCO EMS based processes to filter the messages based on some header properties.
What are EMS Message Selectors?
Message Selector is an API provided by JMS Specifications which is used for filtering of messages from a queue or topic. JMS Message Selector allows a message consumer to specify the messages it is interested in.
Filtering of EMS Messages is done based on an expression which is written in SQL92 syntax. Only those messages which fulfill the condition given in the message selector are consumed by the consumer process while remaining messages remain intact in the queue/topic in the Pending state.
Now let’s proceed with the step by step tibco tutorial which uses message selector to filter EMS Messages.
For this tutorial, I am taking a simple example scenario in which we want to consume only those messages from EMS Queue which have status property “Pass”.
Step 1: Create JMS Connection to the Server
The first thing that we need to do is to drag JMS Connection resource from JMS Palette in our TIBCO Designer Project. Configure JMS Connection based on the required values for your EMS Server. Once configured, use Test Connection button to make sure that everything is fine in terms of connectivity with EMS Server.
Configurations of JMS Connection in my case are shown in below screenshot:
Step 2: Create JMS Application Properties
In this step we will add a shared resource JMS Application Properties from JMS palette in which we will define a property named ”status”. This property will be later used for message selector.
JMS Application Properties configured are shown below:
Step 3: Create a Process to Send JMS Messages to a Queue
In this step, we will create a process which will send message to a queue using JMS Queue Sender activity.
In the configuration tab of JMS Queue Sender activity, specify the Connection as well as the destination queue in the similar way as shown in below screenshot:
In the Advanced tab, choose JMS Application Properties shared resource which was created in the previous step.
In the Input Editor tab, just create a String Element named as “name” in which we will be sending the name of a person. This is shown in below screenshot:
Now go to Input tab and here we need to give some value to status property field as well as name field. Let’s give “Pass” value to status field so that based on our message selector condition, message gets consumed.
Now let’s proceed to the next step in which we will create process to consume EMS message.
Step 4: Create Process to Consume JMS Queue Message with Message Selector
Create a new process and add JMS Queue Receiver from JMS palette as process starter activity. In the configuration tab of this activity, choose JMS Connection and destination queue.
In the Advanced tab, go to Message Selector field. This is the field where we will add expression which will act as a filtering condition for the messages.
As you can see in below screenshot, I have used condition to select only those messages from the queue for which status value is “Pass”.
In the output editor tab, add name element in the same way as you did for JMS Queue Sender process in previous step.
We are not going to add any further logic in the process to keep it simple.
Step 5: Test JMS Message Selector Based Processes in TIBCO Designer
Validate the project to make sure that everything has been designed and configured correctly. Once validated, load both processes (sender and receiver processes) in designer tester and create a job for Sender process.
As you can see below, message has been sent to queue by sender process and has been successfully consumed by receiver process as selector condition (status=”Pass”) was met:
Now if we try to test these processes by giving a different status property value (e.g. Fail), we will see that message doesn’t get consumed by the consumer as Message Selector condition is not fulfilled:
This completes our step by step tutorial on TIBCO EMS Message Selector. Feel free to contact me for any further queries or help. Thanks