• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Message Driven Beans

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic