init
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
package com.eactive.eai.common.jeus;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.ObjectMessage;
|
||||
import javax.jms.Queue;
|
||||
import javax.jms.QueueConnection;
|
||||
import javax.jms.QueueConnectionFactory;
|
||||
import javax.jms.QueueSender;
|
||||
import javax.jms.QueueSession;
|
||||
import javax.jms.Session;
|
||||
|
||||
import com.eactive.eai.common.exception.ExceptionUtil;
|
||||
import com.eactive.eai.common.jms.JmsServiceLocator;
|
||||
import com.eactive.eai.common.util.Logger;
|
||||
|
||||
public class JeusQueueProducer {
|
||||
Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
|
||||
|
||||
QueueConnectionFactory qconFactory = null;
|
||||
|
||||
String connectionFactory = null;
|
||||
String destination = null;
|
||||
|
||||
public JeusQueueProducer(String connectionUrl, String queueName) throws Exception {
|
||||
this.connectionFactory = connectionUrl;
|
||||
this.destination = queueName;
|
||||
}
|
||||
|
||||
public void sendMessage(Serializable object, Properties prop) throws Exception {
|
||||
QueueConnection qcon = null;
|
||||
QueueSession qsession = null;
|
||||
Queue queue = null;
|
||||
QueueSender qsender = null;
|
||||
try {
|
||||
JmsServiceLocator locator = JmsServiceLocator.getInstance();
|
||||
|
||||
qconFactory = locator.getQueueConnectionFactory(connectionFactory);
|
||||
qcon = qconFactory.createQueueConnection();
|
||||
qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
|
||||
queue = locator.getQueue(destination);
|
||||
qsender = qsession.createSender(queue);
|
||||
|
||||
ObjectMessage msg = qsession.createObjectMessage();
|
||||
msg.setObject(object);
|
||||
|
||||
// Properties setting setStringProperties();
|
||||
if (prop != null) {
|
||||
Iterator it = prop.keySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
String key = (String) it.next();
|
||||
String value = prop.getProperty(key);
|
||||
msg.setStringProperty(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
qsender.send(msg);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
// throw new JMSException("RECEAICUL001");
|
||||
throw new JMSException(ExceptionUtil.getErrorCode(e, "RECEAICUL001"));
|
||||
} finally {
|
||||
try {
|
||||
if (qsender != null)
|
||||
qsender.close();
|
||||
} catch (Exception e) {
|
||||
// nothing to do
|
||||
}
|
||||
try {
|
||||
if (qsession != null)
|
||||
qsession.close();
|
||||
} catch (Exception e) {
|
||||
// nothing to do
|
||||
}
|
||||
try {
|
||||
if (qcon != null)
|
||||
qcon.close();
|
||||
} catch (Exception e) {
|
||||
// nothing to do
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.eactive.eai.common.jeus;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.ObjectMessage;
|
||||
import javax.jms.Session;
|
||||
import javax.jms.Topic;
|
||||
import javax.jms.TopicConnection;
|
||||
import javax.jms.TopicConnectionFactory;
|
||||
import javax.jms.TopicPublisher;
|
||||
import javax.jms.TopicSession;
|
||||
|
||||
import com.eactive.eai.common.exception.ExceptionUtil;
|
||||
import com.eactive.eai.common.jms.JmsServiceLocator;
|
||||
import com.eactive.eai.common.util.Logger;
|
||||
|
||||
public class JeusTopicProducer {
|
||||
|
||||
Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
|
||||
|
||||
TopicConnectionFactory topicFactory = null;
|
||||
|
||||
String connectionFactory = null;
|
||||
String destination = null;
|
||||
String correlationID = null;
|
||||
|
||||
public JeusTopicProducer(String connectionUrl, String topicName, String correlationID) throws Exception {
|
||||
this.connectionFactory = connectionUrl;
|
||||
this.destination = topicName;
|
||||
this.correlationID = correlationID;
|
||||
}
|
||||
|
||||
//JMSSender.sendToTopic(eaiMessage, topicConFactory, routeTopicName, null, traceKey, ttl);
|
||||
|
||||
public void sendMessage(Serializable object, Properties prop, long ttl) throws Exception {
|
||||
TopicConnection tcon = null;
|
||||
TopicSession tsession = null;
|
||||
Topic topic = null;
|
||||
TopicPublisher publisher = null;
|
||||
try {
|
||||
if (logger.isDebug()){
|
||||
logger.debug("sendToTopic] connectionFactory = "+connectionFactory);
|
||||
logger.debug("sendToTopic] destination = "+destination);
|
||||
logger.debug("sendToTopic] correlationID =["+correlationID+"]");
|
||||
}
|
||||
JmsServiceLocator locator = JmsServiceLocator.getInstance();
|
||||
topicFactory = locator.getTopicConnectionFactory(connectionFactory);
|
||||
topic = locator.getTopic(destination);
|
||||
|
||||
tcon = topicFactory.createTopicConnection();
|
||||
tsession = tcon.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
|
||||
publisher = tsession.createPublisher(topic);
|
||||
|
||||
// TTL Setting
|
||||
if(ttl > 0) {
|
||||
publisher.setTimeToLive(ttl);
|
||||
}
|
||||
|
||||
ObjectMessage msg = tsession.createObjectMessage();
|
||||
msg.setObject(object);
|
||||
if (correlationID != null)
|
||||
msg.setJMSCorrelationID(correlationID);
|
||||
|
||||
// Properties setting setStringProperties();
|
||||
if(prop!=null) {
|
||||
Iterator it = prop.keySet().iterator();
|
||||
while(it.hasNext()) {
|
||||
String key = (String)it.next();
|
||||
String value = prop.getProperty(key);
|
||||
msg.setStringProperty(key,value);
|
||||
}
|
||||
}
|
||||
publisher.publish(msg);
|
||||
} catch(Exception e) {
|
||||
throw new JMSException(ExceptionUtil.getErrorCode(e,"RECEAICUL002"));
|
||||
} finally {
|
||||
try {
|
||||
if(publisher!=null) publisher.close();
|
||||
} catch(Exception e) {
|
||||
// nothing to do
|
||||
}
|
||||
try {
|
||||
if(tsession!=null) tsession.close();
|
||||
} catch(Exception e) {
|
||||
// nothing to do
|
||||
}
|
||||
try {
|
||||
if(tcon!=null) tcon.close();
|
||||
} catch(Exception e) {
|
||||
// nothing to do
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user