Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

JMS How to send and receive a message

Thread view: 
sss - 21 Nov 2006 19:21 GMT
I figure out how to send a message, but I haven't found out
the how to specify the receiver. I have read some article
saying for PTP messaging, the receiver doesn't need to be
online. But how do you know which user to send when no
body is online?

SK
rxreyn3@gmail.com - 25 Nov 2006 06:50 GMT
So, you have created a JMS server and a topic?

The code for a listner is pretty standard, so I have included one of
mine for an example.

package com.qwest.rx.otto;

import javax.ejb.EJBException;
import javax.ejb.MessageDrivenBean;
import javax.ejb.MessageDrivenContext;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;

import org.apache.log4j.Logger;
import org.hibernate.HibernateException;

/**
* A message-driven bean based on a Queue.
*
* @ejb.bean name="RxWfaEjb" acknowledge-mode="Auto-acknowledge"
destination-type="javax.jms.Queue"
*           subscription-durability="Durable"
transaction-type="Container"
*
* @ejb.transaction type="NotSupported"
*
* @weblogic.pool initial-beans-in-free-pool="2"
max-beans-in-free-pool="4"
*
* @weblogic.message-driven
connection-factory-jndi-name="rx.otto.jms.connectionFactory"
*
destination-jndi-name="rx.otto.wfa.jms.queue"
jms-polling-interval-seconds="1"
*
* @weblogic.transaction-descriptor trans-timeout-seconds="10"
*
* @weblogic.enable-call-by-reference True
*/
public class RxWfaEjb implements MessageDrivenBean, MessageListener
{
   protected static Logger logger = Logger.getLogger("OttoLogger");

   public void ejbRemove() throws EJBException
   {
       // TODO Auto-generated method stub

   }

   public void setMessageDrivenContext(MessageDrivenContext arg0)
throws EJBException
   {
       // TODO Auto-generated method stub

   }

   public void onMessage(Message message)
   {
       logger.debug("Recieved Message From Queue:" + message);
       MapMessage msg = (MapMessage) message;

       if (msg == null)
           return;

       RxWfaWorker worker = null;
       String ticketId = "";
       String status = "";
       try
       {
           ticketId = msg.getStringProperty("ticketId");
           status = msg.getStringProperty("status");
           logger.debug("-< RxOtto >- [ RxWfaEjb ] onMessage (message)
\t=> " + "Working ticket: " + ticketId
                   + " status: " + status);
           worker = new RxWfaWorker();
           worker.ManageTicketStatus(ticketId, status);
       }
       catch (HibernateException e)
       {
           logger.error("-< RxOtto >- [ RxWfaEjb ] onMessage (message)
\t=> "
                   + "Exception encountered while handling some commit
of ticket and status.", e);
       }
       catch (JMSException e)
       {
           logger.error("-< RxOtto >- [ RxWfaEjb ] onMessage (message)
\t=> "
                   + "JMS Excpetion encountered while attempting to
consume message.", e);
       }
   }

   /**
    * Required creation method for message-driven beans.
    *
    * @ejb.create-method
    */
   public void ejbCreate()
   {

   }

}

Ryan

> I figure out how to send a message, but I haven't found out
> the how to specify the receiver. I have read some article
[quoted text clipped - 3 lines]
>
> SK


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.