1 Starting the JMS Server In-Process

The Novell exteNd Messaging Platform's JMS server can be started in-process with your Java server program if necessary. Reasons for doing this include performance improvements for message-intense applications, and creating systems that are easier to manage due to fewer processes.

The example in this section shows how to start the JMS server in-process. This is done using the JMQMessageService class, which support methods to initialize, start and shutdown the server. Below is the source for the InProcess class:

package inProcess;
                                                                           
import java.io.FileInputStream;
                                                                           
import java.util.Properties;
                                                                           
import javax.jms.Topic;
import javax.jms.TextMessage;
import javax.jms.TopicSession;
import javax.jms.TopicPublisher;
import javax.jms.TopicConnection;
import javax.jms.TopicConnectionFactory;
                                                                           
import com.sssw.jms.api.JMQTopic;
import com.sssw.jms.api.JMQMessageService;
import com.sssw.jms.api.JMQTopicConnectionFactory;
                                                                           
public class InProcess
{
    private static final String NAME        = "MyServer";
    private static final String PORT        = "3456";
    private static final String LOGDIR      = ".";
    private static final String STORE       = "cloudscape";
    private static final String JDBC_DRIVER = "COM.cloudscape.core.JDBCDriver";
    private static final String JDBC_URL    = "jdbc:cloudscape:MyServer";
    private static final String USER        = "";
    private static final String PASSWORD    = "";
    private static final String MINPOOL     = "1";
    private static final String MAXPOOL     = "5";
                                                                           
    public static void main(String[] args) throws Exception
    {
    |   // create properties to start server
    |   Properties p = new Properties();
    |                                                                      
    |   // load configuration for server
    |   p.load(new FileInputStream("inprocess.properties"));
    |                                                                      
    |   // alternative: use Cloudscape
//      p.setProperty(JMQMessageService.MSGSVC_NAME, NAME);
//      p.setProperty(JMQMessageService.MSGSVC_PORT, PORT);
//      p.setProperty(JMQMessageService.MSGSVC_LOGDIR, LOGDIR);
//      p.setProperty(JMQMessageService.MSGSVC_STORE, STORE);
//      p.setProperty(JMQMessageService.MSGSVC_JDBC_DRIVER, JDBC_DRIVER);
//      p.setProperty(JMQMessageService.MSGSVC_JDBC_URL, JDBC_URL);
//      p.setProperty(JMQMessageService.MSGSVC_JDBC_USER, USER);
//      p.setProperty(JMQMessageService.MSGSVC_JDBC_PASSWORD, PASSWORD);
//      p.setProperty(JMQMessageService.MSGSVC_JDBC_MINPOOLSIZE, MINPOOL);
//      p.setProperty(JMQMessageService.MSGSVC_JDBC_MAXPOOLSIZE, MAXPOOL);
    |                                                                      
    |   // initialize and start jBroker MQ server
    |   JMQMessageService jms = JMQMessageService.init(p);
    |   jms.start();
    |                                                                      
    |   // print start message
    |   System.out.println(NAME + " running on port " + PORT);
    |                                                                      
    |   // use jBroker MQ API's to bootstrap connection factory and topic
    |   TopicConnectionFactory fac = new JMQTopicConnectionFactory(
    |       JMQTopicConnectionFactory.IIOP_PROTOCOL, "localhost",
    |       "clientId", 3456);
    |   Topic topic = JMQTopic.getTopic("topic0");
    |                                                                      
    |   // create a topic connection the standard way
    |   TopicConnection conn = fac.createTopicConnection();
    |                                                                      
    |   // create a topic session
    |   int mode = TopicSession.AUTO_ACKNOWLEDGE;
    |   TopicSession session = conn.createTopicSession(false, mode);
    |                                                                      
    |   // create a topic publisher
    |   TopicPublisher publisher = session.createPublisher(topic);
    |                                                                      
    |   // send a heartbeat message to topic every 5 seconds
    |   while (true) {
    |   |   Thread.sleep(5000);
    |   |   TextMessage message = session.createTextMessage();
    |   |   message.setText("time is " + System.currentTimeMillis());
    |   |   publisher.publish(message);
    |   }
    }
}
A can be seen from the source, three steps are required to start the JMS server in-process: Note that the database for the server has to be created before it can start. If you wish to create the database in-process, you may use the JMQDatabase class, which supports method to create, destroy and get the version of the JMS server's database.

The server can be shutdown by invoking the shutdown method on JMQMessageService. Once the server has been shutdown, it no longer accepts request on the port. An application typically exits after calling shutdown.

Note that the example above uses the JMQTopicConnectionFactory and JMQTopic classes to bootstrap the client side objects rather than JNDI. Applications that run the JMS server in-process must not use a CosNaming JNDI provider.

Back to top


Copyright © 2000-2003, Novell, Inc. All rights reserved.