JMS配置文档
附件:http://www.blogjava.net/Files/86mang/JMS.doc
1.
登录WebLogic控制台
2.
新建JMS Server
3.
点击“new”按钮
4.
Name改为IbosJMSServer,点击Create a New Store按钮
5.
选中File Store,点击“Next”
6.
Name改为IbosFileStore,点击“OK”。返回到以下页面
7.
选中IbosFileStore,点击“Next”
8.
选中程序所在的Server,点击“Finish”完成。
9.
新建JMS Modules
10.
点击“New”
11.
Name改为IbosSystemModule,点击“Next”
12.
选中程序所在Server,点击“Next”
13.
点击“Finish”完成。
14.
新建QueueConnectionFactory,点击IbosSystemModules
15.
点击“New”
16.
选中“Connection
Factory”,点击“Next”
17.
Name改为IbosQueueConnectionFactory,JNDI Name设为IbosQueueConnectionFactory,点击“Next”
18.
点击“Advanced Targeting”按钮
19.
点击“Create a New Subdeployment”
20.
Subdeployment Name改为IbosSubdeployment,点击“Next“
21.
选中IbosJMSServer,点击“Finish”
22.
Subdeployment选中IbosSubdeployment,点击“Finish”。
23.
新建Queue,点击“New”
24.
选中“Queue”,点击“Next”
25.
Name改为“IbosQueue”,JNDI Name改为“IbosQueue”,点击“Next”
26.
Subdeployment选中“IbosSubdeployment”,点击“Finish”完成。
27.
重新启动weblogic服务。
代码如下:
package ibos.control;
import java.util.List;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.EJB;
import javax.ejb.MessageDriven;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import javax.jms.TextMessage;
import kernel.jpa.JpaUtil;
import kernel.jpa.NamedQueryParameter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@MessageDriven
(mappedName = "IbosQueue",
name = "TransferQueueListener",
activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
}
)
@TransactionAttribute(TransactionAttributeType.NEVER)
public class TransferQueueListener implements MessageListener {
public static Logger log = LoggerFactory.getLogger(TransferQueueListener.class);
public void onMessage(Message message) {
// TextMessage tmsg = (TextMessage) message;
ObjectMessage objMsg = (ObjectMessage) message;
} catch (JMSException e) {
log.error(e.getMessage());
e.printStackTrace();
}
}
}
package ibos.control;
import java.io.Serializable;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
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.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class SendJmsUtil {
public static String Default_Queue_Name = "IbosQueue";
public static int Default_IIOP_PORT = 8080;
public static class QueueManagedObject {
QueueConnection conn;
QueueSession session;
Queue queue;
QueueSender sender;
public QueueManagedObject(QueueConnection conn, QueueSession session,
Queue queue, QueueSender sender) {
super();
this.conn = conn;
this.session = session;
this.queue = queue;
this.sender = sender;
}
}
public static ConcurrentHashMap<String, QueueManagedObject> queueManagedObjectMap = new ConcurrentHashMap<String, QueueManagedObject>();
public static void sendMessage(Serializable obj, String ip) throws Exception {
sendMessage(obj, ip, Default_IIOP_PORT, Default_Queue_Name);
}
public static void sendMessage(Serializable obj, String ip, int port,
String queueName) throws Exception {
QueueManagedObject queueManagedObject = getQueueManagedObject(ip, port,
queueName);
ObjectMessage msg = queueManagedObject.session.createObjectMessage(obj);
queueManagedObject.sender.send(msg);
// queueManagedObject.sender.close();
}
public static QueueManagedObject getQueueManagedObject(String ip, int port,
String queueName) throws Exception {
String key = ip + port+queueName
;
QueueManagedObject queueManagedObject = queueManagedObjectMap.get(key);
if (queueManagedObject == null) {
QueueConnection conn;
QueueSession session;
Queue queue;
QueueSender sender;
Properties props = new Properties();
props.setProperty("java.naming.factory.initial","weblogic.jndi.WLInitialContextFactory");
String url = "t3://" + ip + ":" + port;
props.setProperty("java.naming.provider.url", url);
InitialContext ctx = new InitialContext(props);
QueueConnectionFactory qcf = (QueueConnectionFactory) ctx
.lookup("IbosQueueConnectionFactory");
conn = qcf.createQueueConnection();
session = conn.createQueueSession(false,
QueueSession.AUTO_ACKNOWLEDGE);
queue = (Queue) ctx.lookup(queueName);
sender = session.createSender(queue);
queueManagedObject = new QueueManagedObject(conn, session,
queue, sender);
queueManagedObjectMap.put(key, queueManagedObject);
}
return queueManagedObject;
}
}
附件:http://www.blogjava.net/Files/86mang/JMS.doc
posted on 2010-05-05 10:43
身在半空 阅读(4203)
评论(0) 编辑 收藏