Official sun site gives fair bit of documentation about JMS.
a) A message-driven bean is an enterprise bean that allows J2EE applications to process messages asynchronously. It acts as a JMS message listener, which is similar to an event listener except that it receives messages instead of events. The messages may be sent by any J2EE component--an application client, another enterprise bean, or a Web component--or by a JMS application or system that does not use J2EE technology.
b) The most visible difference between message-driven beans and session and entity beans is that clients do not access message-driven beans through interfaces. Interfaces are described in the section Defining Client Access with Interfaces. Unlike a session or entity bean, a message-driven bean has only a bean class.
c) In several respects, a message-driven bean resembles a stateless session bean.
A message-driven bean's instances retain no data or conversational state for a specific client.All instances of a message-driven bean are equivalent, allowing the EJB container to assign a message to any message-driven bean instance. The container can pool these instances to allow streams of messages to be processed concurrently.
A single message-driven bean can process messages from multiple clients.
d) When a message arrives, the container calls the message-driven bean's onMessage method to process the message.
Please note i am using weblogic9.2 as my application server.
Below is one example implementation for Message Driven Bean
a) Start weblogic server and create a domain named probably JMSDomain1 restart the Domain.Now create a JMS Server and name it as JMSServer1.Again Create a new JMS Module and name it as JMSModule1 and create a queue named EmailQueue for that module JMSModule1.Please donot forget to name target as JMSServer1 for the queue to be created.
b) Now once queue is created please do reconfirm whether queue has been created or not by navigating to domains/JMSDomain1/config/jms/JMSModule1-jms.xml.Generally it is good to have a Error Destination queue for any queue created.
Documentation states
"
The name of the target error destination for messages that have expired or reached their redelivery limit. If no error destination is configured, then such messages are simply dropped. If a message has expired or reached its redelivery limit, and the Expiration Policy is set to Redirect, then the message is moved to the specified Error Destination
"
c) Create EmailMDB.java which behaves as MDB
package com.customware.ejb;
import java.util.*;
import javax.ejb.*;
import javax.jms.*;
import com.customware.util.*;
public class EmailMDB implements MessageDrivenBean, MessageListener {
private MessageDrivenContext context;
// --------------------------------------------------------------
// EJB Methods from MessageDrivenBean interface
// --------------------------------------------------------------
public void ejbCreate() {
System.out.println("EmailMDB: ejbCreate called");
}
public void ejbRemove() {
System.out.println("EmailMDB: ejbRemove called");
}
public void setMessageDrivenContext(MessageDrivenContext context) {
System.out.println("setMessageDrivenContext called");
this.context = context;
}
// --------------------------------------------------------------
// Method from MessageListener interface
// --------------------------------------------------------------
/**
* Take in a MapMessage and use the EmailHelper to send out an email message
*/
public void onMessage(Message message) {
System.out.println("EmailMDB: onMessage called");
MapMessage mapmessage = (MapMessage) message;
try {
// Go through the map message and create a map for sendmail(Map)
Enumeration e = mapmessage.getMapNames();
Hashtable mail = new Hashtable();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
String val = mapmessage.getString(key);
mail.put(key, val);
}
System.out.println("Sending email: EmailHelper.sendmail(mail)");
} catch(Exception e) {
e.printStackTrace();
}
}
}
d) Create EmailClient.java which acts like a client
package com.customware.client;
import java.rmi.*;
import java.util.*;
import javax.jms.*;
import javax.naming.*;
/**
* EmailClient is responsible for sending an email mapmessage to the queue
*/
public class EmailClient {
private static String QUEUE_NAME = "EmailQueue";
private static String CONNECTION_FACTORY = "javax.jms.QueueConnectionFactory";
private static String PROVIDER_URL = "t3://localhost:7001";
private QueueSender sender;
private QueueSession session;
/**
* Constructor: Setup JMS for publishing
*/
public EmailClient() {
try {
Context ctx = getInitialContext();
// Lookup a JMS connection factory
QueueConnectionFactory conFactory =
(QueueConnectionFactory) ctx.lookup(CONNECTION_FACTORY);
// Create a JMS connection
QueueConnection connection = conFactory.createQueueConnection();
// Create a JMS session object
session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
// Lookup a JMS queue
Queue chatQueue = (Queue) ctx.lookup(QUEUE_NAME);
// Create a JMS sender
sender = session.createSender(chatQueue);
} catch(Exception e) {
e.printStackTrace();
}
}
/**
* Method: sendmail(Map mail)
*/
public void sendmail(Map mail) throws Exception {
MapMessage message = session.createMapMessage();
Set keys = mail.keySet();
Iterator i = keys.iterator();
while (i.hasNext()) {
String key = (String) i.next();
String val = (String) mail.get(key);
message.setString(key, val);
}
// send the mapmessage to the Queue
sender.send(message);
}
/**
* Method: getInitialContext()
*
* Login to JNDI
*
* @return Context The initial context
*/
private Context getInitialContext() throws NamingException {
Properties env = new Properties();
env.put("java.naming.factory.initial", "weblogic.jndi.WLInitialContextFactory");
env.put("java.naming.provider.url", PROVIDER_URL);
env.put("java.naming.security.principal", "system");
env.put("java.naming.security.credentials", "weblogic");
return new InitialContext(env);
}
/**
* Static Method: java com.customware.client.EmailClient to_addr [from_addr] [subject] [body]
*/
public static void main(String args[]) throws Exception {
if (args.length == 0) {
System.out.println("Usage: java com.customware.client.EmailClient to_addr [from_addr] [subject] [body]");
System.exit(-1);
}
System.out.println("\nBeginning EmailClient\n");
EmailClient client = new EmailClient();
Hashtable mail = new Hashtable();
mail.put("to", args[0]);
if (args.length > 1) mail.put("from", args[1]);
if (args.length > 2) mail.put("subject", args[2]);
if (args.length > 3) mail.put("body", args[3]);
System.out.println("Sending mail message");
client.sendmail(mail);
}
}
e) Create ejb-jar.xml and weblogic-jar.xml.
f) Finally deploy MDB and run the client.
Hope this helps.
7 comments:
Alzheimer Drug Tv Commercial
http://www.acaiberryscamsreport.com/ - buy acomplia online
It has been helping in helping some patients stop smoking, and is also helpful in the treatment of cocaine addiction.
[url=http://www.acaiberryscamsreport.com/]acomplia pharmacy[/url]
While this medication will cause weight loss on its own, it’s much more effective when it accompanies a proper diet and exercise regiment.
acomplia diet pills
fox book martyrs ebook free http://audiobookscollection.co.uk/de/The-New-Economy-of-the-Inner-City-Restructuring-Regeneration-and-Dislocation-in-the-21st-Century-Metropolis/p227068/ silmarillion ebook [url=http://audiobookscollection.co.uk/A-Companion-to-Middle-High-German-Literature-to-the-14th-Century/p219417/]download ebook video streaming[/url] believing in magic ebook
the ramayana ebook http://audiobooksworld.co.uk/Love-and-the-Single-Heiress/p202408/ evaluation comments ebook [url=http://audiobooksworld.co.uk/William-Aiello/m132044/]ebook pro hacking[/url] scott cunningham ebook
[url=http://onlinemedistore.com/products/arava.htm][img]http://onlinemedistore.com/1.jpg[/img][/url]
business per forma and pharmacy residency program http://onlinemedistore.com/products/avapro.htm i med pharmacy inc [url=http://onlinemedistore.com/products/eulexin.htm]specialty pharmacy houston[/url]
cvs pharmacy coupons http://onlinemedistore.com/products/mobic.htm top pharmacy schools in us [url=http://onlinemedistore.com/products/nexium.htm]nexium[/url]
job discriptions pharmacy http://onlinemedistore.com/products/doxazosin.htm pharmacy automation medication errors [url=http://onlinemedistore.com/products/prazosin.htm]monroe college of pharmacy[/url]
mail order pet pharmacy http://onlinemedistore.com/products/bactroban.htm generic cialis uk online pharmacy [url=http://onlinemedistore.com/products/emsam.htm]emsam[/url]
[url=http://englandpharmacy.co.uk/products/eurax.htm][img]http://onlinemedistore.com/3.jpg[/img][/url]
healix pharmacy http://englandpharmacy.co.uk/products/calan.htm gay friendly pharmacy hiv new york city [url=http://englandpharmacy.co.uk/products/hytrin.htm]professionalism pharmacy[/url]
brooks pharmacy brookline ma http://englandpharmacy.co.uk/catalogue/k.htm pillbox pharmacy weston fl [url=http://englandpharmacy.co.uk/products/accupril.htm]accupril[/url]
cms pharmacy contacts http://englandpharmacy.co.uk/products/zelnorm.htm link online pharmacy [url=http://englandpharmacy.co.uk/products/rhinocort.htm]savon pharmacy 30th hilyard fax[/url]
pay for pharmacy techs http://englandpharmacy.co.uk/products/levitra.htm pharmacy phone solicitation scams [url=http://englandpharmacy.co.uk/products/atrovent.htm]atrovent[/url]
sex dating filipina swingers personals selby south dakota older people dating
dating user profile names http://freeinternetdating.info/personals/swingers-personals-stockholm-south-dakota dating tips key jingling
black female author dating dating japan guide erika fraser dating 30039
france marriage and dating facts http://loveepicentre.com/map/ dating room free chat
ink dating cross cross-examination [url=http://loveepicentre.com/faq/]npr dating[/url] dating ovation guitar
yuying huang shenzhen dating [url=http://loveepicentre.com/faq/]dating two years[/url] gay dating today [url=http://loveepicentre.com/user/wildhottyvanessa/]wildhottyvanessa[/url] adult dating site scams
Post a Comment