實戰JBuilder7+WebLogic7(四)續JMS+Message-Driven Bean (轉)
由於CSDN不能顯示全部文章,要瀏覽全文請瀏覽以下連線
M.htm">
內容簡介:
1。連線MS SERVER2000
2。Session Bean
3。Entity Bean
4。JMS+Message-Driven bean
5。(待續)
全部實戰內容都經過嚴格測試,決無問題,只需嚴格按照文中步驟即可!
ideograph; MARGIN: 13pt 0cm; LINE-HEIGHT: 170%; TEXT-ALIGN: justify; mso-pagination: lines-together">實戰4:JMS:namespace prefix = o ns = "urn:schemas--com::office" />
LOGIC
1. 啟動WebLogic7
2. 開啟,在位址列中輸入:<
3. 輸入名和密碼
4. 在左邊的目錄樹中選中Services->JMS->Connection Factories,單擊右側的Configure a new JMS Connection Factory ,輸入以下資訊:
Configuration->General頁:
Name = MDBDemo Connection Factory
JNDIName= MDBDemoCF
其它不變,單擊Create建立Connection Factory。
Targets->Server頁:
將myserver(名稱)移至右側的列表中,但擊單擊Apply
5. 在左邊的目錄樹中選中Services->JMS->Stores,單擊右側的Configure a new JMileStore,輸入以下資訊:
Configuration->General頁:
Name = MDBDemo Store
Directory: = F:beauser_projectsmyainJMSStores (任意存在的目錄即可)
單擊Create建立JMSFileStore。
6. Services->JMS->Servers,單擊右側的Configure a new JMS Connection Factory ,輸入以下資訊:
Configuration->General頁:
Name = MDBDemo JMSServer
Store = MDBDemo Store
其它不變,單擊Create建立JMS Server。
Targets->Servers頁:
Target = myserver(你的weblogic server的名字)
單擊Configuration->General頁中的Configure Destinations
Name = MDBDemo Topic
JNDIName= MDBDemo Topic
其它不變,單擊Create建立Destination。
配置完畢。
建立Message Driven Bean:
1. 關閉所有工程:File->Close Projects
2. 選擇File->New project
3. 在Name欄中輸入MDBDemo,Directory欄中輸入存放路徑(不要有空格),其他不變,單擊Finish。
4. 選擇File->New->Enterprise->EJB Module單擊OK。
5. 在彈出的對話方塊中,在Name中輸入MDBMoudle, Version選擇:EJB2.0 Compliant其餘不變,單擊OK關閉當前對話方塊。
6. 在右側的EJB Designer 中單擊滑鼠右鍵選擇:Create EJB->Message-Driven Bean,按如下填寫:
Bean Name = MDBDemo
Transaction Type = Container
Destination Name = MDBDemo Topic
Destination Type = x.jms.Topic
其它不變。
7.Project->Make ”MDBModule”, 編譯成功後,右鍵單擊左上角的MDBModule選擇Deploy Options for ”MDBModule.jar”->Deploy,將其釋出至Weblogic。
建立客戶端:
以下是客戶端原始碼,儲存成TestClient.java加入工程後,選擇Run->Run “TestClient.java” using defaults執行即可,可以在weblogic console視窗看到輸出。如果看不到輸出,重起weblogic試一試。
package mdbdemo;
import java..RemoteException;
import java.util.Properties;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;
import javax.jms.TopicConnection;
import javax.jms.TopicConnectionFactory;
import javax.jms.Topiblisher;
import javax.jms.TopicSession;
import javax.ejb.CreateException;
import javax.ejb.RemoveException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemote;
/**
* This class illustrates calling a Message-Driven bean and publishing
* quotes on a topic.
*
* @author Copyright (c) 1998-2002 by BEA Systems, Inc. All Rights Reserved.
*/
public class TestClient {
static private String TOPIC_NAME = "MDBDemo Topic";
private String m_url;
private Context m_context;
private TopicConnection m_topicConnection;
public TestClient(String url)
throws NamingException
{
m_url = url;
try {
//
// Create a context
//
m_context = getInitialContext();
//
// Create the connection and start it
//
TopicConnectionFactory cf =
(TopicConnectionFactory) m_context.lookup("MDBDemoCF");
m_topicConnection = cf.createTopicConnection();
m_topicConnection.start();
}
catch(Exception ex) {
ex.printStackTrace();
}
}
/**
* Runs this example from the command line. Example:
*
* java examples.ejb20.message.Client "t3://localhost:7001"
*
* The parameters are optional, but if any are supplied,
* they are interpreted in this order:
*
* @param url URL such as "t3://localhost:7001" of Server
*/
public static void main(String[] args) throws Exception {
log("nBeginning message.Client...n");
String url = "t3://localhost:7001";
TestClient client = null;
try {
client = new TestClient(url);
} catch (NamingException ne) {
System.exit(1);
}
try {
client.example();
}
catch (Exception e) {
log("There was an exception while creating and using the MDB.");
log("This indicates that there was a problem communicating with the server: "+e);
//e.printStackTrace();
}
log("nEnd message.Client...n");
}
/**
* Runs this example.
*/
public void example()
throws RemoteException, JMSException, NamingException
{
Topic newTopic = null;
TopicSession session = null;
try {
session =
m_topicConnection.createTopicSession(false, // non transacted
Session.AUTO_ACKNOWLEDGE);
newTopic = (Topic) m_context.lookup(TOPIC_NAME);
}
catch(NamingException ex) {
newTopic = session.createTopic(TOPIC_NAME);
m_context.bind(TOPIC_NAME, newTopic);
}
TopicPublisher sender = session.createPublisher(newTopic);
TextMessage tm = session.createTextMessage();
String[] quotes = new String[] {
"BEAS 40 1/8", "SUNW 79 1/2", "IBM 82 1/4", "Hello !"
};
for (int i = 0; i < quotes.length; i++) {
tm.setText(quotes[i]);
sender.publish(tm);
}
}
/**
* Using a Properties object will work on 1.1.x and Java2
* clients
*/
private Context getInitialContext() throws NamingException {
try {
// Get an InitialContext
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, m_url);
return new InitialContext(h);
}
catch (NamingException ex) {
log("We were unable to get a connection to the WebLogic server at "+m_url);
log("Please make sure that the server is running.");
throw ex;
}
}
/**
* This is the Java2 version to get an InitialContext.
* This version relies on the existence of a jndi.properties file in
* the application's classpath.
*
*/
// private static Context getInitialContext()
// throws NamingException
// {
// return new InitialContext();
// }
private static void log(String s) {
System.out.println(s);
}
}
實戰5:JSP呼叫EJB
(待續)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-993140/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 實戰JBuilder7+WebLogic7(續Session bean) (轉)UIWebSessionBean
- JBuilder9+Weblogic7實戰篇Entity Bean運用(四) (轉)UIWebBean
- 實戰JBuilder7+WebLogic7存取MS SQL Server2000(一) (轉)UIWebSQLServer
- JBuilder9.0+Weblogic7.0實戰篇之Session Bean篇 (轉)UIWebSessionBean
- JBuilder9+Weblogic7實戰篇Entity Bean運用(二) (轉)UIWebBean
- JBuilder9+Weblogic7實戰篇Entity Bean運用(三) (轉)UIWebBean
- Spring實戰:裝配bean-自動化裝配beanSpringBean
- ERP實戰演義之四--模組實施上線(轉)
- JBuilder9+Weblogic7實戰篇之Entity Bean運用篇(一) (轉)UIWebBean
- shiro實戰系列(二)之入門實戰續
- Spring裝配Bean(四)SpringBean
- Nginx實戰(四) 限速功能Nginx
- Express 實戰(四):中介軟體Express
- 聯眾升級協議分析 續篇(四) (轉)協議
- Spring的學習與實戰(續)Spring
- CODING 敏捷實戰系列課第四講:從頭搭建持續整合 DevOps 流水線敏捷dev
- 微服務實戰之春雲與刀客(四)——dockerswarm叢集實戰微服務DockerSwarm
- jbuilder7+weblogic7問題UIWeb
- client-go實戰之四:dynamicClientclientGo
- OpenFaaS實戰之四:模板操作(template)
- Tableau實戰 貨架圖分析(四)
- Core Animation實戰四(視覺效果)視覺
- 實戰.Net多執行緒(四)執行緒
- 持續整合之 Spring Boot 實戰篇Spring Boot
- UI自動化實戰進階後續UI
- mysql sql 中實戰小技巧持續更新MySql
- 【轉】微服務實戰微服務
- Turbine實戰(下) (轉)
- BouncyCastle JCE實踐(四) (轉)AST
- gRPC學習之四:實戰四類服務方法RPC
- Spring中bean的四種注入方式SpringBean
- Spring原始碼:Bean生命週期(四)Spring原始碼Bean
- 【Flutter】開發之實戰Widget(四)Flutter
- css揭祕實戰技巧 - 字型排印[四]CSS
- Docker入門實戰 (四) - Docker NetworkDocker
- Kotlin實戰【四】迭代事物:while和forKotlinWhile
- App專案實戰之路(四):UI篇APPUI
- [原創]深入掌握JMS(四):實戰Queue