JBoss 5:JMS

Source: Internet
Author: User

1 adding destination

Modify the Destinations-service.xml file under the Messaging folder under the domain deploy
Add an Mbean:

<mbean code= "Org.jboss.jms.server.destination.QueueService"
  name= "jboss.messaging.destination:service= Queue,name=orderbillingqueue "
  xmbean-dd=" Xmdesc/queue-xmbean.xml ">
  <attribute name=" JNDIName "> queue/orderbillingqueue</attribute>
  <depends optional-attribute-name= "ServerPeer" >
    Jboss.messaging:service=serverpeer
  </depends>
  <depends>jboss.messaging:service=postoffice </depends>
  <attribute name= "Redeliverydelay" >10000</attribute>
  <attribute name= " Maxdeliveryattempts ">3</attribute>
 </mbean>

2 Add MDB:

You can modify the following code according to your own situation

Package ejb3inaction.example.buslogic;

Import Javax.ejb.ActivationConfigProperty;
Import Javax.ejb.MessageDriven;
Import javax.jms.JMSException;
Import Javax.jms.Message;
Import Javax.jms.MessageListener;
Import Javax.jms.ObjectMessage;

@MessageDriven (activationconfig={
  @ActivationConfigProperty (propertyname= "destinationtype",
                Propertyvalue= "Javax.jms.Queue"),         
  @ActivationConfigProperty (propertyname= "Destination", propertyvalue= " Queue/orderbillingqueue ")
}
) public
class Orderbillingmdb implements MessageListener {
 public void onMessage (Message message) {
  ObjectMessage objectmsg = (objectmessage) Message;
  
  try {
   Order order = (order) objectmsg.getobject ();
   Order.setstatus (orderstatus.complete);
   SYSTEM.OUT.PRINTF ("Order is finished.");
  catch (JMSException e) {
   e.printstacktrace ();}}

}

3 Test Code
Modify your situation as you see it:

try {Context context = new InitialContext ();
   ConnectionFactory = (connectionfactory) context.lookup ("/connectionfactory");
  Destination = (destination) context.lookup ("Queue/orderbillingqueue");
  } catch (Namingexception E1) {e1.printstacktrace ();
  } Order Order = New Order ();
  Order.setbidderid (Bidderid);
  Order.setitems (items);
  Order.setshippinginfo (Shippinginfo);
  
  Order.setbidderid (Bidderid);
  
  Order.setstatus (orderstatus.new);
  System.out.println ("Call JMS to remove the required ... from Bill ..., set order status ...");
   try {Connection conn = connectionfactory.createconnection ();
   Session session = Conn.createsession (true, Session.auto_acknowledge);
   ObjectMessage message = Session.createobjectmessage ();
   
   Message.setobject (order);
   
   MessageProducer producer = Session.createproducer (destination);
   
   Producer.send (message);
   Session.commit ();
   Producer.close ();
   Session.close ();
  Conn.close (); } catch (JMSException e) {e.printstacktrace (); }

4 If the context takes something that is empty, add jndi.properties under SRC
Java.naming.factory.initial=org.jnp.interfaces.namingcontextfactory
Java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=localhost:1099

Transferred from: http://www.blogjava.net/guanshuiwang/archive/2010/01/12/jboss_5_jms.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.