jboss ejb3 Message Driven Bean

Super Medium ejb hate. . . . . . . . . . . . . . . . . . .

================================================

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 veryDepressed .)

1.java category.

/*
 * File name: MessageBean .java
 *
 * Creation date: 2009 -2-26
 *
 * Copyright(C) 2009, by Ryoma.
 *
 * The original author : <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 lemom8000@gmail.com

================================================== =========

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("This is my first message driven bean ");
		sender = sess.createSender(queue);
		sender.send(msg);
		sess.close ();
		out.println("The message was sent out, you can to JBoss console to view the output of the Bean ");
	} catch (Exception e) {
		out.println(e.getMessage());
	}

%>

Internet to find examples, test passed.

================================================== =====

EJB good use again quickly. . . . . . . . . . . .

分类:Java 时间:2009-02-27 人气:2771
分享到:
blog comments powered by Disqus

相关文章

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.677 (s). 12 q(s)