This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Message Driven Beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Message Driven Beans " Watch "Message Driven Beans " New topic
Author

Message Driven Beans

Venkatesh Kumar
Ranch Hand

Joined: Aug 08, 2003
Posts: 68
Hi :
I am trying to run a message driven bean example(SimpleMessageEJB) that comes with J2EE 1.3
When I run the client ,the client is supposed to send three messages but it is sending only one message and there is no activity in the console window Where my server is running
can anyone let me know where I am going wrong
_________________________________________________________________________

I have added a JMS destination (Queue) using
j2eeadmin -addJmsDestination jms/MyQueue queue
_________________________________________________________________________
Client code :
import javax.jms.*;
import javax.naming.*;
public class SimpleMessageClient {
public static void main(String[] args) {
Context jndiContext = null;
QueueConnectionFactory queueConnectionFactory = null;
QueueConnection queueConnection = null;
QueueSession queueSession = null;
Queue queue = null;
QueueSender queueSender = null;
TextMessage message = null;
final int NUM_MSGS = 3;
try {
jndiContext = new InitialContext();
} catch (NamingException e) {
System.out.println("Could not create JNDI " +
"context: " + e.toString());
System.exit(1);
}
try {
queueConnectionFactory = (QueueConnectionFactory)
jndiContext.lookup
("java:comp/env/jms/MyQueueConnectionFactory");
queue = (Queue) jndiContext.lookup("java:comp/env/jms/QueueName");
} catch (NamingException e) {
System.out.println("JNDI lookup failed: " +
e.toString());
System.exit(1);
}
try {
queueConnection =
queueConnectionFactory.createQueueConnection();
queueSession =
queueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
queueSender = queueSession.createSender(queue);
message = queueSession.createTextMessage();
for (int i = 0; i < NUM_MSGS; i++) {
message.setText("This is message " + (i + 1));
System.out.println("Sending message: " +
message.getText());
queueSender.send(message);
}
} catch (JMSException e) {
System.out.println("Exception occurred: " + e.toString());
} finally {
if (queueConnection != null) {
try {
queueConnection.close();
} catch (JMSException e) {}
} // if
System.exit(0);
} // finally
} // main
} // class
_________________________________________________________________________
Bean Code
public class SimpleMessageBean implements MessageDrivenBean,
MessageListener {
private transient MessageDrivenContext mdc = null;
private Context context;

public SimpleMessageBean() {
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
 
Consider Paul's rocket mass heater.
 
subject: Message Driven Beans
 
Similar Threads
New To JMS
MDB
P2P using WSAD's embedded JMS- Naming Exception
Message is created but not received by the receiver
jdeveloper look up error for jms