分享
 
 
 

在JBoss上发布Message-Driven Bean的一个痛苦的经历(一)

王朝java/jsp·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

初学Message-Driven Bean,想在JBoss上试一下,却发现这真是一个痛苦的过程。

Message-Driven Bean:

import java.io.Serializable;

import java.rmi.RemoteException;

import javax.ejb.EJBException;

import javax.ejb.MessageDrivenBean;

import javax.ejb.MessageDrivenContext;

import javax.ejb.CreateException;

import javax.naming.*;

import javax.jms.*;

public class LogBean implements MessageDrivenBean,

MessageListener {

private transient MessageDrivenContext mdc = null;

private Context context;

public LogBean() {

System.out.println("In SimpleMessageBean.SimpleMessageBean()");

}

public void setMessageDrivenContext(MessageDrivenContext mdc) {

System.out.println("In "

+ "SimpleMessageBean.setMessageDrivenContext()");

this.mdc = mdc;

}

public void ejbCreate() {

System.out.println("In SimpleMessageBean.ejbCreate()");

}

public void onMessage(Message inMessage) {

TextMessage msg = null;

try {

if (inMessage instanceof TextMessage) {

msg = (TextMessage) inMessage;

System.out.println("MESSAGE BEAN: Message received: "

+ msg.getText());

} else {

System.out.println("Message of wrong type: "

+ inMessage.getClass().getName());

}

} catch (JMSException e) {

e.printStackTrace();

mdc.setRollbackOnly();

} catch (Throwable te) {

te.printStackTrace();

}

} // onMessage

public void ejbRemove() {

System.out.println("In SimpleMessageBean.remove()");

}

} // class

客户端:

TestClient.java

import javax.naming.*;

import javax.jms.*;

import java.util.*;

public class TestClient {

public static void main (String[] args) throws Exception {

// Initialize JNDI

Context ctx = new InitialContext();

// 1: Lookup ConnectionFactory via JNDI

TopicConnectionFactory factory =

(TopicConnectionFactory)

ctx.lookup("ConnectionFactory");

// 2: Use ConnectionFactory to create JMS connection

TopicConnection connection =

factory.createTopicConnection();

// 3: Use Connection to create session

TopicSession session = connection.createTopicSession(

false, Session.AUTO_ACKNOWLEDGE);

// 4: Lookup Desintation (topic) via JNDI

Topic topic = (Topic) ctx.lookup("topic/testTopic");

// 5: Create a Message Producer

TopicPublisher publisher = session.createPublisher(topic);

// 6: Create a text message, and publish it

TextMessage msg = session.createTextMessage();

msg.setText("This is a test message.");

publisher.publish(msg);

}

}

发布过程:

ejb-jar.xml

<?xml version="1.0"?>

<!DOCTYPE ejb-jar>

<ejb-jar>

<enterprise-beans>

<message-driven>

<ejb-name>Log</ejb-name>

<ejb-class>LogBean</ejb-class>

<message-selector></message-selector>

<transaction-type>Bean</transaction-type>

<acknowledge-mode>Auto-acknowledge</acknowledge-mode>

<message-driven-destination>

<destination-type>javax.jms.Topic</destination-type>

</message-driven-destination>

</message-driven>

</enterprise-beans>

</ejb-jar>

jboss.xml

<?xml version="1.0"?>

<jboss>

<enterprise-bean>

<message-driven>

<ejb-name>Log</ejb-name>

<configuration-name>Standard Message Driven Bean</configuration-name>

<destination-jndi-name>topic/testTopic</destination-jndi-name>

</message-driven>

</enterprise-bean>

</jboss>

Log日志:

.....................

2003-04-02 19:48:23,921 INFO [org.jboss.deployment.MainDeployer] Starting deployment of package: file:/F:/jboss/server/default/deploy/ejb-test.jar

2003-04-02 19:48:23,968 INFO [org.jboss.ejb.EjbModule] Creating

2003-04-02 19:48:23,984 INFO [org.jboss.ejb.EjbModule] Deploying Log

2003-04-02 19:48:24,062 INFO [org.jboss.ejb.plugins.jms.JMSContainerInvoker] Creating

2003-04-02 19:48:24,078 INFO [org.jboss.ejb.plugins.jms.JMSContainerInvoker] Created

2003-04-02 19:48:24,078 INFO [org.jboss.ejb.EjbModule] Created

2003-04-02 19:48:24,078 INFO [org.jboss.ejb.EjbModule] Starting

2003-04-02 19:48:24,093 INFO [org.jboss.ejb.plugins.jms.JMSContainerInvoker] Starting

2003-04-02 19:48:24,093 INFO [org.jboss.ejb.plugins.jms.DLQHandler] Creating

2003-04-02 19:48:24,171 INFO [org.jboss.ejb.plugins.jms.DLQHandler] Created

2003-04-02 19:48:24,187 WARN [org.jboss.ejb.plugins.jms.JMSContainerInvoker] destination not found: topic/Log reason: javax.naming.NameNotFoundException: Log not bound<--------错误

2003-04-02 19:48:24,187 WARN [org.jboss.ejb.plugins.jms.JMSContainerInvoker] creating a new temporary destination: topic/Log

2003-04-02 19:48:24,187 INFO [org.jboss.mq.server.jmx.Topic.Log] Creating

2003-04-02 19:48:24,187 INFO [org.jboss.mq.server.jmx.Topic.Log] Created

2003-04-02 19:48:24,187 INFO [org.jboss.mq.server.jmx.Topic.Log] Starting

2003-04-02 19:48:24,187 INFO [org.jboss.mq.server.jmx.Topic.Log] Bound to JNDI name: topic/Log

2003-04-02 19:48:24,203 INFO [org.jboss.mq.server.jmx.Topic.Log] Started

2003-04-02 19:48:24,281 WARN [org.jboss.mq.security.SecurityManager] No SecurityMetadadata was available for Log adding default security conf

2003-04-02 19:48:24,281 INFO [org.jboss.ejb.plugins.jms.DLQHandler] Starting

2003-04-02 19:48:24,296 INFO [org.jboss.ejb.plugins.jms.DLQHandler] Started

2003-04-02 19:48:24,296 INFO [org.jboss.ejb.plugins.jms.JMSContainerInvoker] Started

2003-04-02 19:48:24,296 INFO [org.jboss.ejb.EjbModule] Started

2003-04-02 19:48:24,296 INFO [org.jboss.deployment.MainDeployer] Deployed package: file:/F:/jboss/server/default/deploy/ejb-test.jar

运行结果:

19:52:35,265 WARN [OILServerILService] Connection failure (1).

java.net.SocketException: Connection reset

at java.net.SocketInputStream.read(SocketInputStream.java:168)

at java.io.BufferedInputStream.fill(BufferedInputStream.java:183)

at java.io.BufferedInputStream.read(BufferedInputStream.java:201)

at java.io.ObjectInputStream$PeekInputStream.peek(ObjectInputStream.java

:2133)

at java.io.ObjectInputStream$BlockDataInputStream.readBlockHeader(Object

InputStream.java:2316)

at java.io.ObjectInputStream$BlockDataInputStream.refill(ObjectInputStre

am.java:2383)

at java.io.ObjectInputStream$BlockDataInputStream.read(ObjectInputStream

.java:2455)

at java.io.ObjectInputStream$BlockDataInputStream.readByte(ObjectInputSt

ream.java:2604)

at java.io.ObjectInputStream.readByte(ObjectInputStream.java:845)

at org.jboss.mq.il.oil.OILServerILService$Client.run(OILServerILService.

java:205)

at java.lang.Thread.run(Thread.java:536)

*******************************************************************************************************

jboss.xml,ejb-jar.xml是直接拷贝过来的。对于上面的错误始终不试不得其解,如是就

原封不动的拷贝一个实例,加上UTF-8后竟然上面的错误没有了。心里一阵狂喜,

可是。。。。。。

ejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>

<ejb-jar>

<enterprise-beans>

<message-driven>

<ejb-name>Log</ejb-name>

<ejb-class>LogBean</ejb-class>

<message-selector></message-selector>

<transaction-type>Bean</transaction-type>

<acknowledge-mode>Auto-acknowledge</acknowledge-mode>

<message-driven-destination>

<destination-type>javax.jms.Topic</destination-type>

</message-driven-destination>

</message-driven>

</enterprise-beans>

</ejb-jar>

jboss.xml

<?xml version="1.0" encoding="UTF-8"?>

<jboss>

<enterprise-beans>

<session>

<ejb-name>Log</ejb-name>

<configuration-name>Standard Message Driven Bean</configuration-name>

<destination-jndi-name>topic/testTopic</destination-jndi-name>

</session>

</enterprise-beans>

</jboss>

Log日志:

..........................

2003-04-02 20:15:57,671 INFO [org.jboss.deployment.MainDeployer] Starting deployment of package: file:/F:/jboss/server/default/deploy/ejb-test.jar

2003-04-02 20:15:57,796 INFO [org.jboss.ejb.EjbModule] Creating

2003-04-02 20:15:57,812 INFO [org.jboss.ejb.EjbModule] Deploying Log

2003-04-02 20:15:57,890 INFO [org.jboss.ejb.plugins.jms.JMSContainerInvoker] Creating

2003-04-02 20:15:57,890 INFO [org.jboss.ejb.plugins.jms.JMSContainerInvoker] Created

2003-04-02 20:15:57,890 INFO [org.jboss.ejb.EjbModule] Created

2003-04-02 20:15:57,890 INFO [org.jboss.ejb.EjbModule] Starting

2003-04-02 20:15:57,906 INFO [org.jboss.ejb.plugins.jms.JMSContainerInvoker] Starting

2003-04-02 20:15:57,906 INFO [org.jboss.ejb.plugins.jms.DLQHandler] Creating

2003-04-02 20:15:57,984 INFO [org.jboss.ejb.plugins.jms.DLQHandler] Created

2003-04-02 20:15:58,093 INFO [org.jboss.ejb.plugins.jms.DLQHandler] Starting<--错误没有了。

2003-04-02 20:15:58,093 INFO [org.jboss.ejb.plugins.jms.DLQHandler] Started

2003-04-02 20:15:58,109 INFO [org.jboss.ejb.plugins.jms.JMSContainerInvoker] Started

2003-04-02 20:15:58,109 INFO [org.jboss.ejb.EjbModule] Started

2003-04-02 20:15:58,109 INFO [org.jboss.deployment.MainDeployer] Deployed package: file:/F:/jboss/server/default/deploy/ejb-test.jar

运行结果:

20:20:15,921 INFO [STDOUT] In SimpleMessageBean.SimpleMessageBean()

20:20:15,937 INFO [STDOUT] In SimpleMessageBean.setMessageDrivenContext()

20:20:15,937 INFO [STDOUT] In SimpleMessageBean.ejbCreate()

20:20:15,937 INFO [STDOUT] MESSAGE BEAN: Message received: This is a test messa

ge.

运行结果出来了,但是还是有错误。

20:20:16,031 WARN [OILServerILService] Connection failure (1).

java.net.SocketException: Connection reset

at java.net.SocketInputStream.read(SocketInputStream.java:168)

at java.io.BufferedInputStream.fill(BufferedInputStream.java:183)

at java.io.BufferedInputStream.read(BufferedInputStream.java:201)

at java.io.ObjectInputStream$PeekInputStream.peek(ObjectInputStream.java

:2133)

at java.io.ObjectInputStream$BlockDataInputStream.readBlockHeader(Object

InputStream.java:2316)

at java.io.ObjectInputStream$BlockDataInputStream.refill(ObjectInputStre

am.java:2383)

at java.io.ObjectInputStream$BlockDataInputStream.read(ObjectInputStream

.java:2455)

at java.io.ObjectInputStream$BlockDataInputStream.readByte(ObjectInputSt

ream.java:2604)

at java.io.ObjectInputStream.readByte(ObjectInputStream.java:845)

at org.jboss.mq.il.oil.OILServerILService$Client.run(OILServerILService.

java:205)

at java.lang.Thread.run(Thread.java:536)

虽然结果出来了,但是还是有下面的错误。唉,没办法了,放一下吧,等熟悉了后在

回来看是什么原因吧。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有