This section answers frequently asked questions regarding the usage of JMS APIs for writing simple/complex applications.
Compiling/Running JMS Application using FioranoMQ
Question 1: How do I compile JMS client applications using FioranoMQ?
FioranoMQ installation on Windows, Unix and Solaris comes bundled with batch scripts to compile JMS Applications. On Windows you can find compile-client.bat
in the fmq\bin directory of Fiorano's installation. On Unix environments, you can find compile-client.sh
in the fmq\bin directory of the installation. Please follow the instructions in the batch script to set appropriate environment variables to compile the Client JMS Applications.
Question 2: How do I run JMS client applications using FioranoMQ?
FioranoMQ installation on Windows, Unix and Solaris comes bundled with batch scripts to run JMS Applications. On Windows you can find run-client.bat
in the fmq\bin directory of Fiorano's installation. On Unix environments, you can find run-client.sh
in the fmq\bin directory of the installation. Please follow the instructions in the batch script to set appropriate environment variables to run the Client JMS Applications. FioranoMQ does not require any changes in the VM parameters to run the JMS Clients.
Question 3: How do I run a sample FioranoMQ application under Eclipse?
Following is a step-by-step procedure for running a sample Fiorano application under Eclipse. It has been tested under version 2.0. Before executing these steps, please make sure that your FioranoMQ server is running.
- Create a new project from File > New > Project.
- Select java in the left pane and java Project in the right pane. Click Next.
- Give a project name (say FioranoMQ).
- In the Resource perspective select FioranoMQ, right-click and select properties.
- In the left pane select Java Build Path.
- In the right pane, select Libraries and click Add external Jars.
- Select the following zips and jars from the lib directory of your Fiorano Installer.
- fmq-common.jar
- fmq-rtl.jar
- jndi.jar
- Click OK to close Properties of FioranoMQ dialog box.
- Again select FioranoMQ in the Resources perspective and from Menu bar select File >Import.
- The Import dialog box is displayed. From the (Import) Select dialog box, select File System and click Next.
- In the (Import) File System Dialog box, click Browse and select the directory of the FioranoMQ samples (which you want to run say C:\MyTemp\Fiorano\FIORAN~1\fmq\samples\PubSub\P ubSub). The PubSub folder is added in the left pane, and various samples is added in the right pane.
- From the right pane, select Subscriber.java.
- Click Finish.
- Right-click FioranoMQ in Resource perspective and select rebuild project. This compiles all the java files automatically in this project.
- Double-click Subscriber.java. This opens the source code for Subscriber in the IDE.
- Click java perspective on the left panel. Click Run from the drop-down list on the toolbar and select Java Application from the Run As menu. This launches the class in the active editor, or the selected class in the Navigator, as a local Java application.
- After executing the above step, you can see the following output in the console:
18. Start a publisher in the dos prompt, and publish some messages. These messages are received by the subscriber.
Similar steps can be followed for running the publisher and other FioranoMQ related sample applications in Eclipse.
Question 4: How do I run a sample FioranoMQ application under Visual Age 3.0?
The sample applications, bundled with FioranoMQ, can run successfully, on Visual Age 3.0.
For example, consider a project called Ayrton to which you want to add the samples (in the Workbench Window). In the project Ayrton, there exists a package called Ayrton.
Following are the instructions to compile the samples:
- Right-click the project Ayrton and select Import from the menu. The Import dialog box is displayed. Select the Jar file and click Next.
- The Import from ajar/zip file dialog box is displayed. Choose jndi.jar (located in Fiorano Installation Directory\fmq\lib directory). Select Project:Ayrton and click Finish.
- Repeat the above step for fmq-rtl.jar and fmq-common.jar (located in Fiorano Installation directory\fmq\lib directory).
- Navigate to the package Ayrton, right-click it and select Add > class. A create classDialog Box is displayed. Set the following parameters for this dialog box:
- Project: Ayrton
- Package: Ayrton
- Class Name: Subscriber
- Superclass: java.lang.Object
- check: Browse the class when finished
- check: Compose the class visually
- Click Next. The Attributes dialog box is displayed.
- In the Add import statements, add the following packages:
- java.io.*;
- java.net.*;
- java.utility.*;
- javax.naming.*;
- javax.jms.*;
fiorano.jms.rtl.*;
In Which interface should class implement, add the following:
- javax.jms.MessageListener
- javax.jms.ExceptionListener
- In the Add import statements, add the following packages:
- Click Finish.
- You have a Subscriber class in the Ayrton – Ayrton-- Subscriber Hierarchy. Further, under Subscriber the following would be present:
- Subscriber()
- main(String [ ])
- onException(JMSException)
- onMessage(Message)
- Enter the following code for main(String [ ])
Java code
- Enter the following code for onException(JMSException):
Java code
- Enter the following code for onMessage(Message):
Java code
The above code can also be found in Fiorano's Installation directory/fmq/samples/ PubSub/PubSub/Subscriber.java
Initial Context
Question 5: What is an Initial Context object?
FioranoMQ is a JNDI-compliant messaging server. Initial context is a bound handle to a directory server, which is used to look up administered resources. In FioranoMQ Server, the directory server is embedded into the base MQ Server, hence there is no special lookup object. In addition, FioranoMQ provides for integration with external JNDI compliant directory servers.
Question 6: Does looking up administered object hold up any references in remote VM?
Lookup is a Directory service call, which looks up administered resources and obtains information about the same. Lookups do not result in any resource allocation on the MQ Server, or the corresponding Directory Server.
Question 7: In case of FioranoMQ, what is the name of the InitialContextFactory to be used for JNDI lookup. Also, what does a typical jndi.properties file to be used by FioranoMQclients comprise of?
Incase of FioranoMQ, the Initial Context Factory class is fiorano.jms.runtime.nam-ing.FioranoInitialContextFactory, which can located in fmq-rtl.jar (found in \fmq\lib folder of Fiorano's installation directory) .
Thus, default jndi.properties file, incase of FioranoMQ, is as follows:
This can be used by JMS clients to lookup ConnectionFactory and destination objects from an instance of FioranoMQ server, running on the same machine over TCP (default protocol).
Connection Factory
Question 8: What is the role of a Connection Factory? Do I need multiple Connection factories?
A connection factory is a looked up resource, which contains information (inclusive of the IP address) about a named FioranoMQ Server. A connection factory reference can be used to create multiple connections to a FioranoMQ Server. The following code snippet shows how a single instance of the connection factory can be used to create multiple connections to the MQ Server. So, there is no explicit need to create multiple instance of the Connection Factory.
JMS Connection
Question 9: Do I need different connection instance for every session?
A connection instance can be used to create any number of sessions. Typically a JMS Client creates a connection and all publishers/Subscribers are multiplexed on this connection using one or more sessions. Connection is a heavy weight object and creation of a session should be avoided unless necessary. In some cases, sophisticated client applications may use multiple connections for connecting to multiple JMS Servers (Connection Factories) or for achieving improved performance for speed critical applications.
Question 10: Does JMS allow for creation of multiple connections? When is it required?
The JMS API does allow multiple connections to be created by a single application to either the same or to different JMS servers. Multiple connections might be required, for instance, in cases where different topics of interest are distributed across different servers. If a single application uses a very large number of topics, then multiple connections to a single FioranoMQ server might be of value by helping to distribute the load across multiple threads (since each connection runs in a separate thread on the server).
JMS Sessions
Question 11: What role does a session play in JMS? How heavy weight is a session? What does the statement "executes in a single Threaded Context" mean?
A JMS Session plays two critical roles:
- Manages transactions for publishers and subscribers.
- Serializes the execution of callbacks for all registered consumers of the Session.
Sessions are lightweight objects. Each session is operated upon, by at most, one thread at a time and all callbacks registered on a single session are executed serially. Sessions control the "level of desired concurrency" in the system. To illustrate this point, consider an application that wishes to create subscriptions on topics T1 and T2 on a session S1.
If messages received on both topics T1 and T2 are to be handled by one single process (one message at a time), then the procedure is as follows:
If messages received on T1 and T2 can be processed concurrently, then the approach to follow will be:
In the second case a separate Session objects is used for each of the consumer, allowing both of them to receive messages concurrently from the MQ Server.
Question 12: Can FioranoMQ handle transacted sessions?
FioranoMQ supports client-transacted sessions as defined in the JMS specifications.
Question 13: Can MultipleSessions be created on a single connection?
Yes, you can create large number of sessions on the same connection.
Transactions
Question 14: What are basic transactions?
Transaction is a means of grouping a set of operations as an atomic operation, which guarantees consistency. Publisher and Subscriber transactions can be defined separately as follows:
A Publisher transaction is used to group a set of published messages into an atomic unit. FioranoMQ Server guarantees that either all the messages in this unit are published or none of them are published from the client to the server.
A Subscriber transaction serves to group a set of consumed messages and acknowledges or rollbacks this unit.
Distributed Transactions
Question 15: What are distributed transactions and two phase commit protocols?
Distributed transactions are the implementation of all JMS interfaces starting with "XA" prefix. Distributed transactions span over multiple client and server processes and uses two-phase commit protocols for maintaining consistency of transactions.
Temporary Destinations
Question 16: What is a temporary Topic/Queue? How is it used?
A temporary destination is created on the fly by an application and is destroyed as soon as the connection creating the temporary destination is closed. It is typically used for creating temporary inboxes for receiving directed replies (Request-reply interactions). Name of each temporary destination is guaranteed to be unique.
Publishing Messages
Question 17: What are the modes of Publishing messages? Which one should I use?
Messages can either be published as Non-Persistent messages or Persistent messages. All persistent messages are logged into the FioranoMQ Server. Thus if a message is being published which cannot be missed by any of the Subscribers (active as well as passive) then the message should be marked Persistent.
Question 18: What is the overhead involved in publishing Persistent messages?
Publishing persistent messages comes with an overhead of message logging. When a message is marked Persistent then the publish/commit call does not return until the data is persisted in the off-line database by the MQ Server.
Subscribers
Question 19: What are the types of Subscribers? What are the scenarios in which they are used?
Subscribers can either be Durable Subscribers or Non-Durable Subscribers. If a subscriber wishes to receive all published messages, even those that were published while the subscription was inactive, then the subscriber must register as a durable subscription with the MQServer.
Guaranteed Messaging
Question 20: In FioranoMQ, can messages be persisted/stored on the client side in case the message is not able to reach the FioranoMQ server for some reason?
Client side caching of messages is an important feature that is very beneficial in avoiding any message loss in case of server crash or network failures in a cluster. This feature has been introduced since FioranoMQ 7.1.
Question 21: Which database does Fiorano JMS Server use for storing persistent messages?
FioranoMQ Server uses a proprietary file-based database written in 100% Java. In addition, it uses an index based flat file schema for added performance. The performance of this database is multiple orders better than most generic databases and keeps the server lightweight.
Additionally, FioranoMQ server can be configured to store messages in some RDBMS also. For details of configuration and supported databases please refer to the Chapter 6 Configuring Message Store in the FioranoMQ Handbook.
Question 22: Does Fiorano JMS Server guarantee message delivery?
Yes, all persistent messages are logged in a persistent database and redelivered to the durable subscribers when they log in next time. FioranoMQ server maintains state of each of the durable subscription registered with it.