org.quartz.jobs.ee.jms
public class: SendTopicMessageJob [javadoc |
source]
java.lang.Object
org.quartz.jobs.ee.jms.SendTopicMessageJob
All Implemented Interfaces:
Job
A Job that sends a javax.jms.Message to a
javax.jms.Topic.
The following properties are expected to be provided in the JobDataMap:
JMS_CONNECTION_FACTORY_JNDI - The JNDI name of the JMS Connection Factory.
JMS_DESTINATION_JNDI - The JNDI name of the JMS destination.
JMS_USE_TXN - Whether or not to use a transacted javax.jms.Session.
JMS_ACK_MODE - The acknowledgement mode for the javax.jms.Session.
JMS_MSG_FACTORY_CLASS_NAME - The implementation class name for the JmsMessageFactory.
The following properties are optional
JMS_USER - The JMS user for secure destinations.
JMS_PASSWORD - The JMS password for secure destinations.
The following properties can be used for JNDI support:
INITIAL_CONTEXT_FACTORY - The java.naming.factory.initial setting for JNDI.
PROVIDER_URL - The java.naming.provider.url for JNDI.
| Method from org.quartz.jobs.ee.jms.SendTopicMessageJob Summary: |
|---|
|
execute |
| Method from org.quartz.jobs.ee.jms.SendTopicMessageJob Detail: |
public void execute(JobExecutionContext context) throws JobExecutionException {
TopicConnectionFactory tcf = null;
TopicConnection connection = null;
TopicSession session = null;
Topic topic = null;
TopicPublisher publisher = null;
InitialContext ctx = null;
String user = null;
String pw = null;
final JobDetail detail = context.getJobDetail();
final JobDataMap jobDataMap = detail.getJobDataMap();
try {
ctx = JmsHelper.getInitialContext(jobDataMap);
tcf = (TopicConnectionFactory) ctx
.lookup(JmsHelper.JMS_CONNECTION_FACTORY_JNDI);
if (JmsHelper.isDestinationSecure(jobDataMap)) {
user = jobDataMap.getString(JmsHelper.JMS_USER);
pw = jobDataMap.getString(JmsHelper.JMS_PASSWORD);
connection = tcf.createTopicConnection(user, pw);
} else {
connection = tcf.createTopicConnection();
}
session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
topic = (Topic) ctx.lookup(JmsHelper.JMS_DESTINATION_JNDI);
publisher = session.createPublisher(topic);
String factoryClassName = jobDataMap.getString(JmsHelper.JMS_MSG_FACTORY_CLASS_NAME);
JmsMessageFactory factory = JmsHelper.getMessageFactory(factoryClassName);
Message m = factory.createMessage(jobDataMap, session);
publisher.publish(m);
} catch (NamingException e) {
throw new JobExecutionException(e);
} catch (JMSException e) {
throw new JobExecutionException(e);
} catch (JmsJobException e) {
throw new JobExecutionException(e);
} finally {
JmsHelper.closeResource(publisher);
JmsHelper.closeResource(session);
JmsHelper.closeResource(connection);
}
}
|