Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within EJB and other Jakarta /Java EE Technologies
Search Coderanch
Advance search
Google search
Register / Login
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:
Tim Cooke
Campbell Ritchie
Ron McLeod
Junilu Lacar
Liutauras Vilda
Sheriffs:
Paul Clapham
Jeanne Boyarsky
Henry Wong
Saloon Keepers:
Tim Moores
Tim Holloway
Stephan van Hulst
Piet Souris
Carey Brown
Bartenders:
Jesse Duncan
Frits Walraven
Mikalai Zaikin
Forum:
EJB and other Jakarta /Java EE Technologies
client or consumer register listner?
Samanthi perera
Ranch Hand
Posts: 510
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
this is my
servlet
package MyMdb; import java.io.IOException; import java.io.PrintWriter; import javax.jms.*; import javax.naming.Context; import javax.naming.InitialContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class sendMessage extends HttpServlet { protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); //start the jms stuff try{ Context ctx = new InitialContext(); ConnectionFactory connectionFactory = (ConnectionFactory)ctx.lookup("jms/tConnectionFactory"); Queue queue = (Queue)ctx.lookup("jms/tQueue"); javax.jms.Connection connection = connectionFactory.createConnection(); javax.jms.Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE); MessageProducer messageProducer = session.createProducer(queue); TextMessage message = session.createTextMessage(); message.setText(request.getParameter("message")); System.out.println( "It come from Servlet:"+ message.getText()); messageProducer.send(message); //message sent , it was all //show what we have done in this servlet out.println("<html>"); out.println("<head>"); out.println("<title>Servlet sendMessage</title>"); out.println("</head>"); out.println("<body>"); out.println("<center>"); out.print("Servlet Send this message <h2>"+request.getParameter("message") + "</h2> to this Queue : <h2>"+queue.getQueueName()+"</h2>"); out.println("</center>"); out.println("</body>"); out.println("</html>"); } catch(Exception ex){ ex.printStackTrace(); } out.close(); } // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> /** * Handles the HTTP <code>GET</code> method. * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** * Handles the HTTP <code>POST</code> method. * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** * Returns a short description of the servlet. * @return a String containing servlet description */ @Override public String getServletInfo() { return "Short description"; }// </editor-fold> }
thsi is my message consumer
package mdbs; import javax.annotation.Resource; import javax.ejb.ActivationConfigProperty; import javax.ejb.MessageDriven; import javax.ejb.MessageDrivenContext; import javax.jms.*; @MessageDriven(mappedName = "jms/tQueue", activationConfig = { @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"), @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue") }) public class TMDBBean implements MessageListener { public TMDBBean() { } @Resource private MessageDrivenContext mdc; public void onMessage(Message message) { TextMessage msg = null; try { if (message instanceof TextMessage) { msg = (TextMessage) message; System.out.println("A Message received in TMDB: " + msg.getText()); } else { System.out.println("Message of wrong type: " + message.getClass().getName()); } } catch (JMSException e) { e.printStackTrace(); mdc.setRollbackOnly(); } catch (Throwable te) { te.printStackTrace(); } } }
this is working.Anyway i found in sun site this
A client can register a message listener with a consumer. A message listener is similar to an event listener. Whenever a message arrives at the destination, the JMS provider delivers the message by calling the listener's onMessage method, which acts on the contents of the message.
nyway my client(Servlet) is not register with listner.
But my consumer TMDBBean register listner?
ramprasad madathil
Ranch Hand
Posts: 489
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
nyway my client(Servlet) is not register with listner.
But my consumer TMDBBean register listner?
Yes, your servlet posts the message. And your TMDBBean listens for the message (is the message listener).
ram.
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
which jar files need to run normal JMS application
JMS MessageListner not Consuming Messages(onMessage() is not calling)
A simple JNDI question....
servlet deployment issue on websphere server.
jms queue fetching of message as and when it is posted in asynchronous communication
Enterprise Java integration with Delphi and Free Pascal applications - new release 2019.02
More...