Configuring JMS Servers and Store-and-Forward Agents Best Practices when Using JMSModuleHelper

7 Using JMS Module Helper to Manage Applications 7-1 7 Using JMS Module Helper to Manage Applications The weblogic.jms.extensions.JMSModuleHelper class contains APIs that you can use to programmatically create and manage JMS servers, Store-and-Forward Agents, and JMS system resources. ■ Section 7.1, Configuring JMS System Resources Using JMSModuleHelper ■ Section 7.2, Configuring JMS Servers and Store-and-Forward Agents ■ Section 7.3, JMSModuleHelper Sample Code ■ Section 7.4, Best Practices when Using JMSModuleHelper

7.1 Configuring JMS System Resources Using JMSModuleHelper

JMSModuleHelper 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 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 signature. For more information on JMS system resources, see Configuring Basic JMS System Resources in the Oracle WebLogic Server Administration Console Help.

7.2 Configuring JMS Servers and Store-and-Forward Agents

JMSModuleHelper 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 7-2 Programming JMS for Oracle WebLogic Server 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. For more information, see: ■ Configuring Basic JMS System Resources in the Oracle WebLogic Server Administration Console Help. ■ Understanding the Store-and-Forward Service in the Oracle WebLogic Server Administration Console Help.

7.3 JMSModuleHelper Sample Code

This section provides sample code to create and delete a JMS system resource module.

7.3.1 Creating a JMS System Resource

The module contains a connection factory and a topic. Example 7–1 Create JMS System Resources . . . private static void createJMSUsingJMSModuleHelperContext ctx{ System.out.println \n\n.... Configure JMS Resource for C API Topic Example ....\n\n; try { MBeanHome mbeanHome = MBeanHome ctx.lookupMBeanHome.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.printlnCreated JMSSystemResource + resourceName; create a JMSConnectionFactory CConFac String factoryName = CConFac; String jndiName = CConFac; JMSModuleHelper.createConnectionFactory ctx, resourceName, Using JMS Module Helper to Manage Applications 7-3 factoryName, jndiName, servers[0].getName; JMSConnectionFactoryBean factory = jmsBean.lookupConnectionFactoryfactoryName; System.out.printlnCreated Factory + factory.getName; create a topic CTopic String topicName = CTopic; String topicjndiName = CTopic; JMSModuleHelper.createTopic ctx, resourceName, jmsServerName, topicName, topicjndiName; TopicBean topic = jmsBean.lookupTopictopicName; System.out.printlnCreated Topic + topic.getName; } catch Exception e { System.out.printlnExample configuration failed : + e.getMessage; e.printStackTrace; } } . . .

7.3.2 Deleting a JMS System Resource

The following code removes JMS system resources. Example 7–2 Delete JMS System Resources . . . private static void deleteJMSUsingJMSModuleHelperContext ctx { System.out.println\n\n.... Remove JMS System Resource for C API Topic Example ....\n\n; try { MBeanHome mbeanHome = MBeanHome ctx.lookupMBeanHome.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 7-4 Programming JMS for Oracle WebLogic Server ctx, resourceName ; } catch Exception e { System.out.printlnExample configuration failed : + e.getMessage; e.printStackTrace; } } . . .

7.4 Best Practices when Using JMSModuleHelper

This section provides best practices information when using JMSModuleHelper 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.printlnTrying + command; Queue queue = queueSession.createQueuewlsQueueName; System.out.printlncommand + succeeded after + retryCount - i + 1 + tries in + System.currentTimeMillis - startTimeMillis + millis.; return queue; } catch JMSException je { if retryCount == 0 throw je; } try { System.out.printlncommand + failed, pausing + retryInterval + millis.; Using JMS Module Helper to Manage Applications 7-5 Thread.sleepretryInterval; } catch InterruptedException ignore {} } throw new JMSExceptionout of retries; } You can then call the findQueue method after the JMSModuleHelper class method call to retrieve the dynamically created queue once it becomes available. For example: JMSModuleHelper.createPermanentQueueAsyncctx, domain, jmsServerName, queueName, jndiName; Queue queue = findQueueqsess, jmsServerName, queueName, retry_count, retry_interval; 7-6 Programming JMS for Oracle WebLogic Server 8 Using Multicasting with WebLogic JMS 8-1 8 Using Multicasting with WebLogic JMS Multicasting enables the delivery of messages to a select group of hosts that subsequently forward the messages to subscribers in a cluster. The following sections provide information on the benefits, limitations, and configuration of using multicasting with WebLogic JMS: ■ Section 8.1, Benefits of Using Multicasting