急:請教在MDB中向另一臺機器發訊息session不能建立
我建了一個mdb,名為ContractDraftBean,打算叫它轉發訊息,但是session不能建立:
qSession = qConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
異常如下,哪位大蝦幫忙看看,使用平臺為weblogic 7.0 (jdk1.3.1_02_b02):
weblogic.jms.common.JMSException: Connection not found
at weblogic.jms.dispatcher.InvocableManager.invocableFind(InvocableManager.ja
va:134)
at weblogic.jms.dispatcher.Request.wrappedFiniteStateMachine(Request.java:539
)
at weblogic.jms.dispatcher.DispatcherImpl.dispatchSync(DispatcherImpl.java:27
5)
at weblogic.jms.client.JMSConnection.createSession(JMSConnection.java:374)
at weblogic.jms.client.JMSConnection.createQueueSession(JMSConnection.java:33
4)
at untitled1.MessageHelper.<init>(ContractDraftBean.java:69)
at untitled1.ContractDraftBean.onMessage(ContractDraftBean.java:21)
at weblogic.ejb20.internal.MDListener.execute(MDListener.java:348)
at weblogic.ejb20.internal.MDListener.transactionalOnMessage(MDListener.java:
282)
at weblogic.ejb20.internal.MDListener.onMessage(MDListener.java:263)
at weblogic.jms.client.JMSSession.onMessage(JMSSession.java:2309)
at weblogic.jms.client.JMSSession.execute(JMSSession.java:2232)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:152)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:133)
haha
客戶端程式:
package untitled1;
import javax.ejb.*;
import javax.jms.*;
import java.util.*;
import javax.naming.*;
public class MSGTEST{
private InitialContext ic;
private QueueConnectionFactory qConnectionFactory;
private QueueConnection qConnection;
private QueueSession qSession;
private QueueSender qSender;
private Queue queue;
private TextMessage msg;
private final String JNDI_FACTORY =
"weblogic.jndi.WLInitialContextFactory";
private String JMS_FACTORY = null;
private String QUEUE = null;
private String URL = null;
public MSGTEST(String url,
String factoryName, String queueName) {
try {
this.URL = url;
this.JMS_FACTORY = factoryName;
this.QUEUE = queueName;
ic = getInitialContext(URL);
qConnectionFactory = (QueueConnectionFactory) ic.lookup(JMS_FACTORY);
qConnection = qConnectionFactory.createQueueConnection();
qSession = qConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDG
E);
queue = (Queue) ic.lookup(queueName);
qSender = qSession.createSender(queue);
msg = qSession.createTextMessage();
qConnection.start();
}
catch (Exception e) {
e.printStackTrace();
}
}
private InitialContext getInitialContext(String url) throws
NamingException {
Properties properties = null;
try {
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
properties.put(Context.PROVIDER_URL, url);
return new InitialContext(properties);
}
catch (Exception e) {
e.printStackTrace();
return null;
}
}
public void sendMessage(String message) throws JMSException {
try {
msg.setText(message);
qSender.send(msg);
}
catch (Exception ex) {
throw new JMSException(ex.getMessage());
}
finally {
close();
}
}
public void close() throws JMSException {
qSender.close();
qSession.close();
qConnection.close();
}
public static void main(String[] args) {
MSGTEST messageHelper = new MSGTEST("t3://localhost:7001",
"ContractDraftCF", "ContractDraftQueue");
try {
messageHelper.sendMessage("haha");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
訊息驅動bean程式如下:
package untitled1;
import javax.ejb.*;
import javax.jms.*;
import java.util.*;
import javax.naming.*;
public class ContractDraftBean implements MessageDrivenBean, MessageListener {
MessageDrivenContext messageDrivenContext;
public void ejbCreate() throws CreateException {
/**@todo Complete this method*/
}
public void ejbRemove() {
/**@todo Complete this method*/
}
public void onMessage(Message msg) {
try {
TextMessage tm=(TextMessage) msg;
String str = tm.getText();
System.out.println(str);
MessageHelper messageHelper = new MessageHelper("t3://pl:7001",
"ContractDraftCF", "ContractDraftQueue");
messageHelper.sendMessage(str);
}
catch (JMSException e) {
e.printStackTrace();
}
}
public void setMessageDrivenContext(MessageDrivenContext messageDrivenContex
t) {
this.messageDrivenContext = messageDrivenContext;
}
}
class MessageHelper {
private InitialContext ic;
private QueueConnectionFactory qConnectionFactory;
private QueueConnection qConnection;
private QueueSession qSession;
private QueueSender qSender;
private Queue queue;
private TextMessage msg;
private final String JNDI_FACTORY =
"weblogic.jndi.WLInitialContextFactory";
private String JMS_FACTORY = null;
private String QUEUE = null;
private String URL = null;
public MessageHelper(String url,
String factoryName, String queueName) {
try {
this.URL = url;
this.JMS_FACTORY = factoryName;
this.QUEUE = queueName;
ic = getInitialContext(URL);
qConnectionFactory = (QueueConnectionFactory) ic.lookup(JMS_FACTORY);
qConnection = qConnectionFactory.createQueueConnection();
qSession = qConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDG
E);
queue = (Queue) ic.lookup(queueName);
qSender = qSession.createSender(queue);
msg = qSession.createTextMessage();
qConnection.start();
}
catch (Exception e) {
e.printStackTrace();
}
}
private InitialContext getInitialContext(String url) throws
NamingException {
Properties properties = null;
try {
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
properties.put(Context.PROVIDER_URL, url);
return new InitialContext(properties);
}
catch (Exception e) {
e.printStackTrace();
return null;
}
}
public void sendMessage(String message) throws JMSException {
try {
msg.setText(message);
qSender.send(msg);
}
catch (Exception ex) {
throw new JMSException(ex.getMessage());
}
finally {
close();
}
}
public void close() throws JMSException {
qSender.close();
qSession.close();
qConnection.close();
}
public static void main(String[] args) {
MessageHelper messageHelper = new MessageHelper("t3://pl:7001",
"ContractDraftCF", "ContractDraftQueue");
try {
messageHelper.sendMessage("haha");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
qSession = qConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
異常如下,哪位大蝦幫忙看看,使用平臺為weblogic 7.0 (jdk1.3.1_02_b02):
weblogic.jms.common.JMSException: Connection not found
at weblogic.jms.dispatcher.InvocableManager.invocableFind(InvocableManager.ja
va:134)
at weblogic.jms.dispatcher.Request.wrappedFiniteStateMachine(Request.java:539
)
at weblogic.jms.dispatcher.DispatcherImpl.dispatchSync(DispatcherImpl.java:27
5)
at weblogic.jms.client.JMSConnection.createSession(JMSConnection.java:374)
at weblogic.jms.client.JMSConnection.createQueueSession(JMSConnection.java:33
4)
at untitled1.MessageHelper.<init>(ContractDraftBean.java:69)
at untitled1.ContractDraftBean.onMessage(ContractDraftBean.java:21)
at weblogic.ejb20.internal.MDListener.execute(MDListener.java:348)
at weblogic.ejb20.internal.MDListener.transactionalOnMessage(MDListener.java:
282)
at weblogic.ejb20.internal.MDListener.onMessage(MDListener.java:263)
at weblogic.jms.client.JMSSession.onMessage(JMSSession.java:2309)
at weblogic.jms.client.JMSSession.execute(JMSSession.java:2232)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:152)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:133)
haha
客戶端程式:
package untitled1;
import javax.ejb.*;
import javax.jms.*;
import java.util.*;
import javax.naming.*;
public class MSGTEST{
private InitialContext ic;
private QueueConnectionFactory qConnectionFactory;
private QueueConnection qConnection;
private QueueSession qSession;
private QueueSender qSender;
private Queue queue;
private TextMessage msg;
private final String JNDI_FACTORY =
"weblogic.jndi.WLInitialContextFactory";
private String JMS_FACTORY = null;
private String QUEUE = null;
private String URL = null;
public MSGTEST(String url,
String factoryName, String queueName) {
try {
this.URL = url;
this.JMS_FACTORY = factoryName;
this.QUEUE = queueName;
ic = getInitialContext(URL);
qConnectionFactory = (QueueConnectionFactory) ic.lookup(JMS_FACTORY);
qConnection = qConnectionFactory.createQueueConnection();
qSession = qConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDG
E);
queue = (Queue) ic.lookup(queueName);
qSender = qSession.createSender(queue);
msg = qSession.createTextMessage();
qConnection.start();
}
catch (Exception e) {
e.printStackTrace();
}
}
private InitialContext getInitialContext(String url) throws
NamingException {
Properties properties = null;
try {
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
properties.put(Context.PROVIDER_URL, url);
return new InitialContext(properties);
}
catch (Exception e) {
e.printStackTrace();
return null;
}
}
public void sendMessage(String message) throws JMSException {
try {
msg.setText(message);
qSender.send(msg);
}
catch (Exception ex) {
throw new JMSException(ex.getMessage());
}
finally {
close();
}
}
public void close() throws JMSException {
qSender.close();
qSession.close();
qConnection.close();
}
public static void main(String[] args) {
MSGTEST messageHelper = new MSGTEST("t3://localhost:7001",
"ContractDraftCF", "ContractDraftQueue");
try {
messageHelper.sendMessage("haha");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
訊息驅動bean程式如下:
package untitled1;
import javax.ejb.*;
import javax.jms.*;
import java.util.*;
import javax.naming.*;
public class ContractDraftBean implements MessageDrivenBean, MessageListener {
MessageDrivenContext messageDrivenContext;
public void ejbCreate() throws CreateException {
/**@todo Complete this method*/
}
public void ejbRemove() {
/**@todo Complete this method*/
}
public void onMessage(Message msg) {
try {
TextMessage tm=(TextMessage) msg;
String str = tm.getText();
System.out.println(str);
MessageHelper messageHelper = new MessageHelper("t3://pl:7001",
"ContractDraftCF", "ContractDraftQueue");
messageHelper.sendMessage(str);
}
catch (JMSException e) {
e.printStackTrace();
}
}
public void setMessageDrivenContext(MessageDrivenContext messageDrivenContex
t) {
this.messageDrivenContext = messageDrivenContext;
}
}
class MessageHelper {
private InitialContext ic;
private QueueConnectionFactory qConnectionFactory;
private QueueConnection qConnection;
private QueueSession qSession;
private QueueSender qSender;
private Queue queue;
private TextMessage msg;
private final String JNDI_FACTORY =
"weblogic.jndi.WLInitialContextFactory";
private String JMS_FACTORY = null;
private String QUEUE = null;
private String URL = null;
public MessageHelper(String url,
String factoryName, String queueName) {
try {
this.URL = url;
this.JMS_FACTORY = factoryName;
this.QUEUE = queueName;
ic = getInitialContext(URL);
qConnectionFactory = (QueueConnectionFactory) ic.lookup(JMS_FACTORY);
qConnection = qConnectionFactory.createQueueConnection();
qSession = qConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDG
E);
queue = (Queue) ic.lookup(queueName);
qSender = qSession.createSender(queue);
msg = qSession.createTextMessage();
qConnection.start();
}
catch (Exception e) {
e.printStackTrace();
}
}
private InitialContext getInitialContext(String url) throws
NamingException {
Properties properties = null;
try {
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
properties.put(Context.PROVIDER_URL, url);
return new InitialContext(properties);
}
catch (Exception e) {
e.printStackTrace();
return null;
}
}
public void sendMessage(String message) throws JMSException {
try {
msg.setText(message);
qSender.send(msg);
}
catch (Exception ex) {
throw new JMSException(ex.getMessage());
}
finally {
close();
}
}
public void close() throws JMSException {
qSender.close();
qSession.close();
qConnection.close();
}
public static void main(String[] args) {
MessageHelper messageHelper = new MessageHelper("t3://pl:7001",
"ContractDraftCF", "ContractDraftQueue");
try {
messageHelper.sendMessage("haha");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
相關文章
- 請教java中如何根據ip判斷另一臺機器在網路中是通的Java
- Telegram 建立機器人併發訊息機器人
- 請教mina處理訊息?需要建立訊息佇列?佇列
- 請教在同一臺機器上配置weblogic的clusterWeb
- 請教hibernate 中session問題Session
- 本地JBoss中部屬了一個MDB,如何讓它訂閱另一臺機器上的JBoss中的topic
- 請教open session in viewSessionView
- 急,急,急,請教高手struts驗證的問題!
- Python向kafka發訊息PythonKafka
- 遇到一個關於session id的問題,向大家請教!Session
- OC訊息機制,訊息轉發機制
- 向高段位請教
- 向大家請教開發流程的問題
- 請教一個在Session Bean中使用JDBC的問題SessionBeanJDBC
- 向高手請教hibernate
- 新手請教:action 中 scope="session"之後怎麼用?Session
- 向banq老師請教:ddd中的值物件物件
- 在vmare中建立centos虛擬機器CentOS虛擬機
- 請教在eclispe中如何配置使用jiveLisp
- EJBCommand模式向banq請教模式
- 請教資料庫連線問題??急!資料庫
- 請教 NIO 中物件流通訊的問題物件
- 請教banq disruptor中ringBuffer能不能做排序排序
- 訊息佇列批次收發訊息,請避開這 5 個坑!佇列
- WebRTC中的訊息機制Web
- 關於open session in view,想在此請教!SessionView
- 請教tomcat session丟失問題TomcatSession
- 請教:JBoss伺服器不能釋放資源的問題伺服器
- 將資料庫從一臺機器複製到另一臺機器上資料庫
- 請教高手們,急救!!!怎麼樣在jbuilderx建立ejb元件,UI元件
- 微信開發中的訊息驗證與訊息回覆
- 「視訊」PISCES要先派機器人去外太空,幫人類建立另一個家園?機器人
- 威少親授,胯下變向急停跳投教學
- 請教各位大蝦:在JBoss下使用JMS通訊機制遇到的問題
- 請教各位大俠,如果查詢一個已建立的有狀態session bean?SessionBean
- 給微信伺服器發訊息伺服器
- 請教!急!急!修改文字檔案一行的內容 根據“=”分割。
- 請教分散式事務的具體處理:急!!!!分散式