================================================
To configure a Message Driven Bean in a different application server parameters are not the same.
Currently only passed the test jboss.
Message Driven Bean part 2 contains a configuration file and a java category. (The book that it does not need configuration files can also be, I have not been successful, with a total reported is not found in the very郁闷.)
1.java category.
/*
* 文件名: MessageBean.java
*
* 创建日期: 2009-2-26
*
* Copyright(C) 2009, by Ryoma.
*
* 原始作者: <a href="mailto:lemom8000@gmail.com">Ryoma</a>
*
*/
package com.mdb.ejb.impl;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.Message;
import javax.jms.MessageListener;
/**
*
*
* @author <a href="mailto:lemom8000@gmail.com">Ryoma</a>
*
* @version $Revision$
*
* @since 2009-2-26
*/
@MessageDriven(activationConfig =
{
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/myQueue")
})
public class MessageBean implements MessageListener {
/*
* (non-Javadoc)
*
* @see javax.jms.MessageListener#onMessage(javax.jms.Message)
*/
public void onMessage(Message message) {
System.out.println("MessageBean:" + message.getClass());
System.out.println("MessageBean:" + message);
}
} Red part of the application in different not the same. MessageListener are to be achieved. Yellow myQueue necessary configuration in the configuration file.
2. Configuration file. xxxxx-service.xml under deploy or him on the following directory.
<mbean code="org.jboss.mq.server.jmx.Queue" name="jboss.mq.destination:service=Queue,name=myQueue">
<depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
</mbean>
<mbean code="org.jboss.jms.server.destination.QueueService"
name="jboss.messaging.destination:service=Queue,name=PrivateDLQ"
xmbean-dd="xmdesc/Queue-xmbean.xml">
<depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
<depends>jboss.messaging:service=PostOffice</depends>
</mbean> Can be two ways, first is to find online, the second is on the server in the example-destinations-service.xml found. The second in the document has much writing, the specific property do not know what did not used to find documents, has found give me a hair
================================================== =========
Call the following methods:
<%@ page contentType="text/html; charset=GBK"%>
<%@ page import="javax.naming.*, java.text.*, javax.jms.*, java.util.Properties"%>
<%
QueueConnection cnn = null;
QueueSender sender = null;
QueueSession sess = null;
Queue queue = null;
try {
Properties props = new Properties();
props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.provider.url", "localhost:1099");
props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
InitialContext ctx = new InitialContext(props);
QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
cnn = factory.createQueueConnection();
sess = cnn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
queue = (Queue) ctx.lookup("queue/myQueue");
} catch (Exception e) {
out.println(e.getMessage());
}
try {
TextMessage msg = sess.createTextMessage("这是我的第一个消息驱动Bean");
sender = sess.createSender(queue);
sender.send(msg);
sess.close ();
out.println("消息已经发送出去了,你可以到JBoss控制台查看Bean的输出");
} catch (Exception e) {
out.println(e.getMessage());
}
%> Internet to find examples, test passed.
================================================== =====
EJB good use again quickly. . . . . . . . . . . .







