急:請教在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();
}
}
}
相關文章
- Telegram 建立機器人併發訊息機器人
- 向高段位請教
- Python向kafka發訊息PythonKafka
- 如何向大牛請教問題?
- 在vmare中建立centos虛擬機器CentOS虛擬機
- 訊息佇列批次收發訊息,請避開這 5 個坑!佇列
- SseEmitter 伺服器向客戶端推送訊息MIT伺服器客戶端
- python收到MQTT訊息後再發http請求PythonMQQTHTTP
- 在 Windows 上搭建 MQTT 訊息伺服器WindowsMQQT伺服器
- 在Unity中實現一個簡單的訊息管理器Unity
- 檢視瀏覽器請求的session 瀏覽器怎麼檢視session瀏覽器Session
- 釘釘的自定義機器人突然不能用了,用 webhook 發群訊息沒反應,大家有遇到的嗎機器人WebHook
- 中國開發者利好訊息!
- 快速向 Google Chat 傳送訊息Go
- 訊息機制篇——初識訊息與訊息佇列佇列
- iOS 訊息轉發機制Demo解析iOS
- RestCloud MQ訊息整合平臺,實現訊息自動記錄及重發RESTCloudMQ
- 恆訊科技指導:如何快速將域名從一臺主機轉移到另一臺主機?
- 女友機器人等6則AI訊息機器人AI
- 關於精益轉型,我們該向誰請教?
- (原創) odoo17中在訊息主題(mail.thread)中傳送訊息時,是否通知訊息作者進行控制OdooAIthread
- 千牛自動傳送訊息怎麼發?來試試UiBot千牛訊息傳送機器人UI機器人
- 用程式碼理解 ObjC 中的傳送訊息和訊息轉發OBJ
- 建立訊息佇列(Kafka)源表佇列Kafka
- 企業在機器學習應用中需要吸取的經驗和教訓機器學習
- Objective-C中的訊息轉發Object
- Python自制微信機器人:群發訊息、自動接收好友Python機器人
- Java微信公眾平臺開發(四)--回覆訊息的分類及實體的建立Java
- Java微信公眾平臺開發(三)--接收訊息的分類及實體的建立Java
- iOS進階之訊息轉發機制iOS
- 在Nodejs下與Rabbitmq訊息伺服器通訊(node-amqp)NodeJSMQ伺服器
- 你知道關閉頁面時怎麼向後臺傳送訊息嗎?
- 在 Fedora 中使用 Cockpit 建立虛擬機器KPI虛擬機
- 在CentOS上建立虛擬機器以及RedisCentOS虛擬機Redis
- 直播原始碼網站,訊息圖示在收到訊息時展示訊息條數原始碼網站
- VMware ESXI磁碟下載虛擬機器遷移到另一臺VMware ESXI虛擬機
- 在“江海詩教”活動中執教《竹石》
- 據訊息稱:微軟正在開發windows10原生虛擬機器微軟Windows虛擬機
- Latex檔案本機能正常編譯,但在另一臺電腦不能編譯的解決方法編譯