Manage users with JMS

Use JMS to build a unified user management framework within your enterprise

1 2 Page 2
Page 2 of 2
  1. Using Java Directory and Naming Interface (JNDI), look up a TopicConnectionFactory for the JMS provider that hosts the desired topic. Since TopicConnectionFactory is an administered object, a system administrator must provide the JNDI name for this object. A TopicConnectionFactory's sole purpose is to create connections.
  2. Use this TopicConnectionFactory object to create a TopicConnection, which represents a direct connection to the JMS server.
  3. Create a JMS TopicSession. This object creates message producers and consumers (publishers and subscribers) and manages the flow of messages.
  4. Look up a JMS Topic with JNDI. Like TopicConnectionFactory, Topic is an administered object, so a system administrator must provide the JNDI name for it.
  5. Create a publisher to the topic just set up in Step 4.
  6. Create the individual JMS subscribers for ERP, CRM, and other applications, and set these subscribers as message listeners to the topic obtained in Step 4.
  7. The TopicConnection created in Step 2 is initially stopped. Start the connection by calling its start() method.

Publish updates

The sequence diagram shown in Figure 3 illustrates the process of updating user profiles.

Figure 3. Publish updates to user profiles. Click on thumbnail to view full-size image.

The update process is as follows:

  1. Obtain a singleton instance of UserServiceFactory.
  2. Use this factory object to obtain an IUserService interface to JMSUserService by calling the getService() method on UserServiceFactory.
  3. Pass user profile parameters that need updates to the IUserService object.
  4. IUserService prepares an XML string representing the action to be performed and the user profile parameters involved (as explained in the section, "Prepare the Message").
  5. IUserService gets a singleton instance of JMSClientManager.
  6. From this instance, IUserService gets a reference to Publisher and sends the XML string to it for publication.
  7. Publisher encapsulates the XML message into a javax.jms.TextMessage and publishes it to javax.jms.TopicPublisher, which then sends the message to the JMS topic.

The code below creates a new user tbrown in the system, updates his profile, and then deletes the user from the system:

   // Get instance of user service as an interface
   IUserService userService = UserServiceFactory.getInstance().getService();
   // Create user with given profile
   userService.createUser("tbrown", "Timothy", "Brown", "");
   // Update this user's profile
   userService.updateUser("tbrown", "Timothy", "Brown", "");
   // Delete user from system

IUserService updates the database and notifies JMSClientManager, which then uses the publisher to publish the user's profile to the various subscribers. As you can see, the underlying mechanism for updating all applications in the system is completely transparent to the developer—the developer's task reduces to just one line of code each for user creation, user update, and user deletion.


The framework described above provides the following benefits:

  • It offers a robust system for user profile maintenance across heterogeneous applications. The framework ensures that user profiles always remain synchronized among these applications—regular data synchronization is unnecessary.
  • Implementation cost is low; you don't need to purchase a third-party product for maintaining synchronized lists of user information. A customized framework can be developed in-house with few resources.
  • Only the master database requires backup. This database is considered authoritative.
  • Using JMS at the center of the architecture provides these additional benefits:

    • A standardized API for all applications and services within the framework.
    • Guaranteed message delivery. With unreliable protocols, acknowledgement of data receipt must be built in at the application layer.
    • The publish-subscribe messaging model allows one-to-many broadcast of information.
    • New applications may be dynamically added to the system simply by creating a subscriber for the application and subscribing this subscriber to the JMS topic.
    • The JMS vendor handles the communication infrastructure's complexity, allowing developers to focus on the system's higher-level architecture.


Our framework does not support the ability to publish user profiles from individual applications. User profiles must be modified only through the Web interface, not by individual applications. Any updates made to a user profile directly in an application are likely to be lost once an updated profile for that user is published to the topic.

Also, user groups and access control lists still need to be maintained elsewhere, for which more sophisticated tools are available.

Possible enhancements

The framework is elementary, but completely usable. You can apply some enhancements and make the system more sophisticated:

  • Not all subscribers may need to receive all messages. To filter messages by content, JMS provides a properties-based message selection mechanism called message selectors. Message selectors cause the JMS provider to evaluate message headers and properties prior to sending messages to the subscriber applications. Use message selectors in the framework if you need to selectively publish messages to subscribers.
  • On a client failure, or when a new client is added, a custom program can publish all existing user profiles to the JMS topic, which the newly registered subscribers can then receive.
  • In case of a suspected out-of-sync situation, an on-demand sync feature can be provided through the Web interface.
  • You can author custom JavaServer Pages (JSP) tags to handle user profile updates, making programming easier.

JMS and XML: The perfect pair

This article presented a real-life, enterprise JMS example that integrates business applications in a simple, flexible, and guaranteed fashion. JMS links enterprise systems together through reliable messages, even over unreliable networks, and promotes decoupling and scalability of the system at the same time.

XML's use is particularly important here, as it provides a standard data format for information exchange between heterogeneous systems. Although JMS was not designed specifically for carrying XML payloads, in practice, it provides an excellent means for transporting XML. Together, JMS and XML offer a viable solution for many enterprise integration problems.

Amit Goel is a senior developer at eSilicon Corp. He has been developing object-oriented applications for several years. He holds a bachelor's degree in electronics from Indian Institute of Technology Delhi and a master's degree in computer science from Virginia Tech. You can learn more about him at David Marshall is the platform architect for eSilicon Corp. He has more than 22 years of experience developing distributed tools and enterprise applications like ERP, using relational database systems, multiple operating systems, and distributed client/server, Internet, and Java architectures. David holds a master's degree in computer science from Clemson University and coauthored US Patent number 5,758,351, a system and method for the creation and use of surrogate information system objects.

Learn more about this topic

1 2 Page 2
Page 2 of 2