Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to send message from Web Component  RSS feed

L Goundalkar
Ranch Hand
Posts: 395
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to know how to send message to a Message Driven Bean residing in EJB container from
1. Web Component
2. Application Client
3. Another Entity Bean
4. Non J2EE client.
If you provide me any tutorial link on this it would be really helpful.
Thanks for the time.
Sergiu Truta
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No matter from where you want to send JMS messages, the code is pretty much like in the following client. I have copied a simple client, hope you can figure out from this.
package j2eepatterns.tests;
* <p>Title: </p>
* <p>Description: This is the client class for the MessageFacade</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author Sergiu Truta
* @version 1.0
import j2eepatterns.businessdelegate.dto.*;
import javax.naming.*;
import javax.jms.*;
import java.util.*;
import java.text.*;
import java.math.BigDecimal;
public class TestPostMessageMDB {
public static void main(String[] args){
QueueConnectionFactory queueConFactory = null;
QueueConnection queueCon = null;
QueueSession queueSession = null;
Queue queue = null;
QueueSender qsend = null;
ObjectMessage objectMessage = null;
java.util.Properties p = new java.util.Properties();
p.put("java.naming.factory.url.pkgs","org.jboss.naming rg.jnp.interfaces");
InitialContext iContext = new InitialContext(p);
queueConFactory = (QueueConnectionFactory)iContext.lookup( "ConnectionFactory" );
queue = (Queue)iContext.lookup("queue/DLQ");
}catch(NamingException e){
System.out.println("JNDI look up failed: " + e.toString());
queueCon = queueConFactory.createQueueConnection();
queueSession = queueCon.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
qsend = queueSession.createSender(queue);
MessageDTO messageDTO = new MessageDTO();
messageDTO.setTitle("What can you guys say about CMP versus BMP?");
messageDTO.setDescription("Read Ed Roman's EJB 2nd edition.You can find it on");
messageDTO.setOwner(new UserDTO(new BigDecimal(29)));
messageDTO.setRootMessage(new Double(97));
//this is an object message that should not get to our PostMessageMDB
objectMessage = queueSession.createObjectMessage("this object message should not reach the repository!");
//this is an object message that should get to our PostMessageMDB
objectMessage = queueSession.createObjectMessage(messageDTO);
//this is a text message that should not get to our PostMessageMDB
TextMessage tm = null;
tm = queueSession.createTextMessage();
tm.setText("This is a text");
}catch(JMSException e){
System.out.println("JMS exception occurrred : " + e.toString());
if(queueCon != null){
}catch (JMSException e){

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!