wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes MDB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "MDB" Watch "MDB" New topic
Author

MDB

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MDB