8 Using JMS Module Helper to Manage Applications

Learn how to create and manage JMS servers, Store-and-Forward agents, and JMS system resources by using JMSModuleHelper.

See weblogic.jms.extensions.JMSModuleHelper.

Configuring JMS System Resources Using JMSModuleHelper

You can manage a system module, including the JMS resources it contains by providing the domain MBean or by providing the initial context to the administration server in the API signatures defined by the JMSModuleHelper class.

The JMSModuleHelper class provides the following API signatures to manage a system module and JMS resources, such as queues and topics:

  • Create a resource

  • Create and modify resource

  • Delete a resource

  • Find and modify a resource

  • Find using a template

See Configuring Basic JMS System Resources in the Administering JMS Resources for Oracle WebLogic Server.

Configuring JMS Servers and Store-and-Forward Agents

You can manage JMS servers and Store-and-Forward agents by providing the domain MBean or by providing the initial context to the administration server in the API signature defined by the JMSModuleHelper class.

The JMSModuleHelper class provides the following method APIs to manage JMS servers and Store-and-Forward agents:

  • Create JMS servers and Store-and-Forward Agents

  • Delete JMS servers and Store-and-Forward Agents

  • Deploy JMS servers and Store-and-Forward Agents

  • Undeploy JMS servers and Store-and-Forward Agents

Related Topics

JMSModuleHelper Sample Code

Learn how to create and delete a JMS system resource module by following instructions in the sample code.

Creating a JMS System Resource

The module contains a connection factory and a topic.

Example 8-1 shows how to create JMS system resources.

Example 8-1 Create JMS System Resources

.
.
.
private static void createJMSUsingJMSModuleHelper(Context ctx){
System.out.println(
     "\n\n.... Configure JMS Resource for C API Topic Example ....\n\n"); 

     try {

     MBeanHome mbeanHome = 
        (MBeanHome) ctx.lookup(MBeanHome.ADMIN_JNDI_NAME);
        DomainMBean domainMBean = mbeanHome.getActiveDomain();
        String domainMBeanName = domainMBean.getName();
        ServerMBean[] servers = domainMBean.getServers();

      String jmsServerName = "examplesJMSServer";

//
// create a JMSSystemResource "CapiTopic-jms"
//
     String resourceName = "CapiTopic-jms";
     JMSModuleHelper.createJMSSystemResource(
        ctx,
         resourceName,
         servers[0].getName());
         JMSSystemResourceMBean jmsSR =
              JMSModuleHelper.findJMSSystemResource(
                    ctx,
                    resourceName);
          JMSBean jmsBean = jmsSR.getJMSResource();
     System.out.println("Created JMSSystemResource " + resourceName);

//
// create a JMSConnectionFactory "CConFac"
//
     String factoryName = "CConFac";
     String jndiName = "CConFac";
     JMSModuleHelper.createConnectionFactory(
        ctx,
        resourceName,
         factoryName, 
         jndiName,
          servers[0].getName());
     JMSConnectionFactoryBean factory =           jmsBean.lookupConnectionFactory(factoryName);
     System.out.println("Created Factory " + factory.getName());

//
// create a topic "CTopic"
//
     String topicName = "CTopic";
     String topicjndiName = "CTopic"; 
     JMSModuleHelper.createTopic(
        ctx,
        resourceName,
        jmsServerName,
        topicName, 
        topicjndiName);

     TopicBean topic = jmsBean.lookupTopic(topicName);
     System.out.println("Created Topic " + topic.getName());
     } catch (Exception e) {
         System.out.println("Example configuration failed :" + e.getMessage());
        e.printStackTrace();
     } 
}
.
.
.

Deleting a JMS System Resource

The following code removes JMS system resources.

Example 8-2 shows how to delete the JMS system resources.

Example 8-2 Delete JMS System Resources

.
.
.
private static void deleteJMSUsingJMSModuleHelper(Context ctx ) {

     System.out.println("\n\n.... Remove JMS System Resource for C API Topic Example ....\n\n");


     try {

        MBeanHome mbeanHome = 
           (MBeanHome) ctx.lookup(MBeanHome.ADMIN_JNDI_NAME);
           DomainMBean domainMBean = mbeanHome.getActiveDomain();
           String domainMBeanName = domainMBean.getName();
            ServerMBean[] servers = domainMBean.getServers();

     String jmsServerName = "examplesJMSServer";

//
// delete JMSSystemResource "CapiTopic-jms"
//
     String resourceName = "CapiTopic-jms";
     JMSModuleHelper.deleteJMSSystemResource(
        ctx,
        resourceName
         );
     } catch (Exception e) {
        System.out.println("Example configuration failed :" + e.getMessage());
        e.printStackTrace();
     } 
}
.
.
.

Security Considerations for Anonymous Users

If your application environment depends on using anonymous users, you can create a security role for Anonymous and then apply a policy to the weblogic.management.mbeanservers JNDI resource that allow access by users in that role.

See Security for WebLogic Server MBeans in Developing Custom Management Utilities Using JMX for Oracle WebLogic Server.

Since WebLogic Server 10.3.6, the JMSModuleHelper does not support anonymous lookup (using -Dweblogic.management.anonymousAdminLookupEnabled=true) to comply with the existing WebLogic security model.

Best Practices When Using JMSModuleHelper

Understand the best practices to follow when using the JMSModuleHelper class to configure JMS servers and resources.

  • Trap for null MBean objects (such as servers, JMS servers, modules) before trying to manipulate the MBean object.

  • A create or delete method call can fail without throwing an exception. In addition, a thrown exception does not necessarily indicate that the method call failed.

  • The time required to create the destination on the JMS server and propagate the information to the JNDI namespace can be significant. The propagation delay increases if the environment contains multiple servers. It is recommended that you test for the existence of the queue or topic, respectively, using the session createQueue() or createTopic() method, rather than perform a JNDI lookup. By doing so, you can avoid some of the propagation-specific delay.

    For example, the following method, findQueue(), attempts to access a dynamically created queue, and if unsuccessful, sleeps for a specified interval before retrying. A maximum retry count is established to prevent an infinite loop.

private static Queue findQueue (
 QueueSession queueSession,
 String jmsServerName, 
 String queueName, 
 int retryCount,
 long retryInterval
) throws JMSException
{
  String wlsQueueName = jmsServerName + "/" + queueName;
  String command = "QueueSession.createQueue(" + 
       wlsQueueName + ")";
  long startTimeMillis = System.currentTimeMillis();
  for (int i=retryCount; i>=0; i--) {
       try {
        System.out.println("Trying " + command);
        Queue queue = queueSession.createQueue(wlsQueueName);
        System.out.println(command + "succeeded after " +
               (retryCount - i + 1) + " tries in " +
               (System.currentTimeMillis() - startTimeMillis) + 
               " millis.");
        return queue;
       } catch (JMSException je) {
        if (retryCount == 0) throw je;
       }
       try {
        System.out.println(command + "> failed, pausing " +
               retryInterval + " millis.");
        Thread.sleep(retryInterval);
       } catch (InterruptedException ignore) {}
  }
  throw new JMSException("out of retries");
}

You can then call the findQueue() method after the JMSModuleHelper class method call to retrieve the dynamically created queue after it becomes available. For example:

JMSModuleHelper.createPermanentQueueAsync(ctx, domain, jmsServerName, 
 queueName, jndiName);
Queue queue = findQueue(qsess, jmsServerName, queueName,
 retry_count, retry_interval);