Creating Subscribers for a Durable Subscription Best Practice: Always Close Failed JMS ClientIDs

6-20 Programming JMS for Oracle WebLogic Server ■ Configure a connection factory subscription sharing policy in Oracle WebLogic Server Administration Console Help. ■ Section 13, Developing Advanced PubSub Applications.

6.7.5 Creating Subscribers for a Durable Subscription

You can create subscribers for a durable subscription using the following TopicSession methods: public TopicSubscriber createDurableSubscriber Topic topic, String name throws JMSException public TopicSubscriber createDurableSubscriber Topic topic, String name, String messageSelector, boolean noLocal throws JMSException You must specify the name of the topic for which you are creating a subscriber, and the name of the durable subscription. You may also specify a message selector for filtering messages and a noLocal flag described later in this section. Message selectors are described in more detail in Section 6.9, Filtering Messages. If you do not specify a messageSelector, by default all messages are searched. An application can use a JMS connection to both publish and subscribe to the same topic. Because topic messages are delivered to all subscribers, an application can receive messages it has published itself. To prevent this, a JMS application can set a noLocal flag to true. The noLocal value defaults to false. Durable subscriptions are stored within the file or database.

6.7.6 Best Practice: Always Close Failed JMS ClientIDs

As a best practice, JMS clients should always call the close method instead of allowing the application to rely on the JVMs garbage collection to clean up failed JMS connections. This is particularly important for durable subscription ClientIDs because the JMS Automatic Reconnect feature keeps a reference to such failed JMS connections. Therefore, always use connection.close to clean up your connections. Also, consider using a finally block to ensure that your connection resources are cleaned up. Otherwise, WebLogic Server allocates system resources to keep the connection available. The following snippet demonstrates using close and finally in a JMS client to clean up failed connection resources: JMSConnection con = null; try { con = cf.createConnection; con.setClientIDFred; Note: Valid durable subscription names cannot include the following characters: comma ,, equals =, colon :, asterisk , percent , or question mark?. Managing Your Applications 6-21 Do some IO stuff; } finally { if con = null con.close; } For more information about the JMS Automatic Reconnect feature, see Section 14.1, Automatic JMS Client Failover.

6.7.7 Deleting Durable Subscriptions