急:请教在MDB中向另一台机器发消息session不能建立

03-11-19 xfzhu2003
我建了一个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();

}

}

}

oldma
2003-11-19 11:16
两台weblogic server的名字是不是一样了?

banq
2003-11-20 09:16
Connection not found错误

使用JMS,需要设置容器的COnnectionFactory和Query/Topic,如果应用程序无法正常使用,也就无法发信息,实际问题大部分出在这个环节。

oldma
2003-11-20 10:55
> Connection not found错误

> 使用JMS,需要设置容器的COnnectionFactory和Query/Topic?> 如果应用程序无法正常使用,也就无法发信息,实际问题大部

呵呵,不是真的吧,连COnnectionFactory和Query/Topic都没有设置,MDB是怎么target的

xfzhu2003
2003-11-25 10:03
什么意思?weblogic server名字都是myserver,而且不在MDB中都能发送及成功接收

猜你喜欢
2Go 1 2 下一页