• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to send message from Web Component

 
Ranch Hand
Posts: 395
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
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.
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
try{
p.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
p.put(Context.PROVIDER_URL,"localhost:1099");
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());
}
try{
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 theserverside.com");
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!");
qsend.send(objectMessage);
//this is an object message that should get to our PostMessageMDB
objectMessage = queueSession.createObjectMessage(messageDTO);
qsend.send(objectMessage);
//this is a text message that should not get to our PostMessageMDB
TextMessage tm = null;
tm = queueSession.createTextMessage();
tm.setText("This is a text");
qsend.send(tm);
}catch(JMSException e){
System.out.println("JMS exception occurrred : " + e.toString());
}finally{
if(queueCon != null){
try{
queueCon.close();
}catch (JMSException e){
}
}
}
}
}

Cheers
 
reply
    Bookmark Topic Watch Topic
  • New Topic