Task 2.5 – JMS Message Selectors A message selector allows the JMS consumer to filter undesired, incoming JMS messages before they are processed. A selector is defined as a boolean expression combining header fields and properties in a way reminiscent of the WHERE statement of an SQL query. Assume the following scenarios: 1. An insurance application uses a message queue to collect complains from its clients. The application needs to select from the queue all the messages that are come from chemists and physicists that work for the University of Stuttgart. 2. A producer wants to receive a message as soon as it is posted to his queue an order of at least 100 pieces of the article with the inventory number “SFW374556-02”. Define for each of the above scenarios a selector and describe which header fields and properties have to be included in the message. Task 2.6 – JMS Topics Define a hierarchy of JMS topics that describes the German stock market. The topic German stock market should include the indexes (DAX, MDAX, TECDAX,…) as well as different industrial sectors as (sub-)topics. The companies enlisted in the stock market can be represented in different sectors, e.g. a company can publish its messages over the Topic DAX, as well as over a topic “Diversified industrials”. In the scope of the JMS Topic hierarchy resulting from above, consider the following cases: ● BMW wants to publish messages about its stocks. To which (sub-)topics should those messages be published? ● A customer wants to receive the messages from every company listed in the DAX index, as well as from Puma (which is listed in MDAX). Which topics has the customer to subscribe to? Task 2.7 Chat Application 1 For this task you may use NetBeans IDE 7.0.1 Java EE Bundle (comes already with GlassFish Server Open Source Edition 3.1.1: http://netbeans.org/downloads/index.html) or any other tooling of your choice. Your task is to develop a chat application that run from command-line using JMS pub/sub API1. In a nutshell, the chat application receives the name of the user as launch parameter (i.e. as args in the method main). After its launch, the chat application reads the messages given input by the user from command line (System.in). Each message is terminated by a carriage return (i.e. the message is not processed by the chat application unless the user presses the “return” button). The messages are published on a predefined JMS topic. Incoming messages are pulled by the very same JMS topic, which the chat application must subscribe. All incoming and outgoing messages should be also displayed on the console in the form: [name of the originating user]: [message text] The following hints should help you while developing your chat application: 1 This task is based on the Chapter 2 from the book “Java Message Service” by Richard Monson and David A. Chappell
Create the Connection Factory and Topic required for the chat application in your GlassFish using the management console. Create a NamingProperties.java (extends Hashtable) with the configurations of Connection Factory name, Topic name etc. Your application will need to obtain a JNDI connection to the JMS messaging server and look up all required JMS administered objects; create the corresponding JMS session objects as well as JMS publisher and subscriber (here you have to set a JMS message listener), start the JMS connection to the predefined topic. These steps could be done e.g. in the constructor of the class Chat. That Chat class should implement the interface the javax.jms.MessageListener and implement the corresponding onMessage method to react on the messages received from the topic. For reading the messages typed by the user on the command line, you may use the method readLine shown here: http://myy.helia.fi/~karte/readline_in_java.html Create a method writeMessage(String text) to form a JMS message and publish it on the topic whenever user has typed a message on the console. Additional Task: modify your chat application to filter out the messages from specific users.