Tuesday, December 12, 2006

Implementing JMS with Spring: Message Driven POJO

The previous post described how to implement a JMS messaging client using Spring JMS. This post will describe how to implement the Message listener as a spring Message driven POJO. Follow these steps to implement the Message driven POJO
  1. Create the Message Driven POJO: The only requirement for the Message Driven POJO is to implement the MessageListener interface. The following listing shows the code for the MDP
    public class SpringMDP implements MessageListener {
    public void onMessage(Message message) {
    try {
    System.out.println(((TextMessage) message).getText());
    } catch (JMSException ex) {
    throw new RuntimeException(ex);
    }
    }
    }
    SpringMDP.java

  2. Create the bean definition in applicationContext.xml file.
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    <!-- this is the Message Driven POJO (MDP) -->
    <bean id="messageListener" class="jms.SpringMDP" />

    <bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
    <property name="environment">
    <props>
    <prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
    <prop key="java.naming.provider.url">t3://localhost:20001</prop>
    </props>
    </property>
    </bean>
    <bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiTemplate">
    <ref bean="jndiTemplate" />
    </property>
    <property name="jndiName">
    <value>jms/connectionFactory</value>
    </property>
    </bean>

    <bean id="queue" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiTemplate">
    <ref bean="jndiTemplate" />
    </property>
    <property name="jndiName">
    <value>jms/testQueue</value>
    </property>
    </bean>


    <bean id="listenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <property name="concurrentConsumers" value="5" />
    <property name="connectionFactory" ref="connectionFactory" />
    <property name="destination" ref="queue" />
    <property name="messageListener" ref="messageListener" />
    </bean>
    </beans>
    WEB-INF/applicationContext.xml

    The Message listener container handles all the required functions for making the Simple POJO a Message Driven POJO.

  3. Update Web.xml to include a listener for spring.
    <listener>  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

127 comments:

  1. I am getting this error. Any Ideas.

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'connectionFactory' defined in ServletContext resource [/WEB-INF/applicationContext-spring.xml]: Invocation of init method failed; nested exception is org.omg.CORBA.COMM_FAILURE: vmcid: SUN minor code: 203 completed: No
    Caused by:
    org.omg.CORBA.COMM_FAILURE: vmcid: SUN minor code: 203 completed: No
    at com.sun.corba.se.impl.logging.ORBUtilSystemException.writeErrorSend(Unknown Source)

    ReplyDelete
  2. Hi, I wrote a MDB, deployed it to the weblogic server ( I am not using web) .

    I used your code, and was able to publish successfully, even without using your applicationcontext.xml. Somehow it is reading from the weblogic-ejb-jar.xml instead. How can I make it such that it is reading from your application context xml file? Please advise...

    ReplyDelete
  3. Any idea how to start/stop listner if something goes wrong without having to restart the server.

    In Webpshere we can access the listner incase something went wrong and start the listner can something we configure something in spring that can access the listner to help admins

    ReplyDelete
  4. Abhi your things doesnot work JndiDestination resolver does not work,getting exception createMapIfPossible error. Then jms/queue name does not support ,tried giving servername/queuename , it says could not find.I had strong hope in your example but I am disappointed.

    ReplyDelete
  5. this kind of sucks . . . isnt the idea of MDB that you can throttle how many are spawned etc . . ? i mean here you are saving nothing more than allowing the calling code to go ahead, you can still crush your server . . .MDB is the right way to go not listener driven POJO

    ReplyDelete
  6. Thanks For sharing Your information The Information Shared Is Very Valuable Please Keep updating Us Time Just Went On Redaing The Article Python Online Course Devops Online Course Data Science Online Course Aws Science Online Course

    ReplyDelete

  7. Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.

    digital marketing courses mumbai

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. If people that write articles cared more about writing great material like you, more readers would read their content. It's refreshing to find such original content in an otherwise copy-cat world. Thank you so much.

    SEO Services in Kolkata
    Best SEO Services in Kolkata
    SEO Company in Kolkata
    Best SEO Company in Kolkata
    Top SEO Company in Kolkata
    Top SEO Services in Kolkata
    SEO Services in India
    SEO Company in India

    ReplyDelete
  10. Your amazing piece of writing kept me hooked to it. According to me, you have successfully covered all the major points which this article demanded.
    SAP training in Kolkata
    Best SAP training in Kolkata
    SAP training institute in Kolkata

    ReplyDelete
  11. Very nice blogs!!! i have to learning for lot of information for this sites...Sharing for wonderful information.Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing, data science online course

    ReplyDelete
  12. thanks for sharing your expertise and also the time it took to post!!

    Data Science Training in Hyderabad

    ReplyDelete
  13. This blog is really helpful regarding all educational knowledge I earned. It covered a great area of subject which can assist a lot of needy people. Everything mentioned here is clear and very useful

    AI Training in Hyderabad

    ReplyDelete
  14. Really impressed! Everything is very open and very clear clarification of issues. It contains truly facts. Your website is very valuable. Thanks for sharing.
    data science course in Hyderabad

    ReplyDelete
  15. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
    FullStack development training
    Java training
    Spring Boot and Micro services training

    AWS Training courses and certification

    ReplyDelete
  16. Awesome. You have clearly explained …Its very useful for me to know about new things. Keep on blogging.

    Data Science Training in Gurgaon
    Data Analytics Training in Gurgaon

    ReplyDelete
  17. Very nice article. I enjoyed reading your post. very nice share. I want to twit this to my followers. Thanks !. ExcelR Business Analytics Courses

    ReplyDelete
  18. I’m happy I located this blog! From time to time, students want to cognitive the keys of productive literary essays composing. Your first-class knowledge about this good post can become a proper basis for such people. nice one
    best data science courses in hyderabad

    ReplyDelete
  19. I recently came across your article and have been reading along. I want to express my admiration of your writing skill and ability to make readers read from the beginning to the end. I would like to read newer posts and to share my thoughts with you.
    data science certification

    ReplyDelete
  20. Hii…It was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly.

    Data Science Training in Chennai

    Data Science Course in Chennai

    ReplyDelete
  21. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. Great work
    data scientist certification

    ReplyDelete
  22. this is really nice to read..informative post is very good to read..thanks a lot!
    data scientist course

    ReplyDelete
  23. Amazing, glad to see this great post. I trust this think help any beginner for their amazing work. By the way a debt of gratitude is in order for share this magnificence from…

    AI Training in Hyderabad

    ReplyDelete
  24. Wonderful illustrated information. I thank you for that. No doubt it will be very useful for my future projects. Would like to see some other posts on the same subject!
    data scientist training in hyderabad

    ReplyDelete
  25. Every weekend I used to visit this site, because I wish for enjoyment, for the reason that this this web page donations in fact good funny material too

    야한동영상
    오피헌터
    마사지블루
    건마탑

    ReplyDelete
  26. Totally loved your article. Looking forward to see more more from you. 스포츠토토

    ReplyDelete
  27. Great post! I am actually getting ready to across this information, is very helpful my friend. Also great blog here with all of the valuable information you have. Keep up the good work you are doing here. Feel free to visit my website; 안전놀이터

    ReplyDelete
  28. Your style is so unique in comparison to other people I’ve read stuff from. Thanks for posting when you have the opportunity, Guess I will just book mark this page. Feel free to visit my website; 온라인카지노

    ReplyDelete
  29. I am very happy when these blog posts read because blog post was written in a good manner and write on a good topic. Thanks for sharing valuable information. Feel free to visit my website; 카지노

    ReplyDelete

  30. Infycle Technologies, the top software training institute and placement center in Chennai offers the best
    Data science training in Chennai
    for freshers, students, and tech professionals at the best offers. In addition to Digital Marketing, other in-demand courses such as DevOps, Big Data, Cyber Security, Python, Selenium, Big Data, Java, Power BI, Oracle will also be trained with 100% practical classes. Call 7504633633 to get more info and a free demo.

    ReplyDelete
  31. Thanks designed for sharing such a nice thought, paragraph is nice, thats why i have read
    it entirely

    https://www.totosafeguide.com

    ReplyDelete
  32. Great Post for Beginner to understand. I finally found great post here. Thanks for information. Keep sharing more articles. 바카라사이트

    ReplyDelete
  33. I truly like your style of blogging. I added it to my preferred's blog webpage list and will return soon…

    ReplyDelete
  34. 360DigiTMG, the top-rated organisation among the most prestigious industries around the world, is an educational destination for those looking to pursue their dreams around the globe. The company is changing careers of many people through constant improvement, 360DigiTMG provides an outstanding learning experience and distinguishes itself from the pack. 360DigiTMG is a prominent global presence by offering world-class training. Its main office is in India and subsidiaries across Malaysia, USA, East Asia, Australia, Uk, Netherlands, and the Middle East.

    ReplyDelete
  35. You really make it look so natural with your exhibition however I see this issue as really something which I figure I could never understand. It appears to be excessively entangled and incredibly expansive for me.

    ReplyDelete
  36. I have a mission that I’m just now working on, and I have been at the look out for such information.
    cyber security course malaysia

    ReplyDelete

  37. Two full thumbs up for this magneficent article of yours. I've really enjoyed reading this article today and I think this might be one of the best article that I've read yet. Please, keep this work going on in the same quality. data science course

    ReplyDelete
  38. Very appreciated post. Thank you for sharing this post with us.

    토토

    ReplyDelete
  39. Thanks for sharing a nice article really such a wonderful site you have done a great job once more thanks a lot

    토토

    ReplyDelete
  40. Thanks for sharing such great information.

    경마사이트

    ReplyDelete
  41. This is my first time go to see at here and i am really happy to read everything at single place.

    경마

    ReplyDelete
  42. Finally I got a website from where I be capable of truly take helpful facts regarding my study and knowledge.

    릴게임

    ReplyDelete
  43. This website and I conceive this internet site is really informative ! Keep on putting up!

    토토사이트

    ReplyDelete
  44. I am genuinely thankful to the holder of this web page who has shared this wonderful paragraph at this place
    cyber security course in malaysia

    ReplyDelete
  45. Hi! this is often nice article you shared with great information. 릴게임

    ReplyDelete
  46. I’m still learning from you, as I’m trying to achieve my goals. 메이저사이트

    ReplyDelete
  47. Very nice article and straight to the point. Thank you. 파칭코

    ReplyDelete
  48. It is the superset of data mining in which data is collected. It is then cleansed with the help of statistical algorithms to transform it into a model that can efficiently represent data.

    ReplyDelete
  49. Data mining helps the business grow more because it can predict the future of a product. Data mining is helpful inside the organization and outside of the organization.

    ReplyDelete
  50. I believe that Microsoft has free paper dolls available on their website too – they used to anyway!
    카지노사이트

    ReplyDelete
  51. This is a GREAT idea. I have never thought about making these before. Love it! Definitely on my to do list!!
    카지노사이트

    ReplyDelete
  52. I too was wondering if you make the actual paper doll magnetic? The doll is to big for the magnetic sheet.
    바둑이사이트

    ReplyDelete
  53. It would help if you thought that the data scientists are the highest-paid employees in a company.data science course in kochi

    ReplyDelete
  54. I have express a few of the articles on your website now, and I really like your style of blogging. I added it to my favorite’s blog site list and will be checking back soon…data scientist course in chennai”

    ReplyDelete
  55. It’s not how it’s about where? Get trained at 360DigiTMG, the best Data Analytics training institute, and experience the power of technical knowledge. Hone your skills with the ground-breaking curriculum. data analytics course in gurgaon

    ReplyDelete
  56. Thanks for giving great kind of information. nice work keep it up thanks for sharing the knowledge.

    ReplyDelete
  57. I will have to agree don’t push it take what you can and move up to the next level in the long run you will come out to be a winner, love this video by the way and thanks

    토토사이트웹

    ReplyDelete
  58. Are you still unsuccessful in your search for the top online data science courses? Several platforms provide data science courses, but it's crucial to focus on those that meet your requirements and allow for domain specialisation. A few training opportunities in data science are included below for those who are just entering the profession.best data science institute in nashik with placement

    ReplyDelete
  59. Thank you for providing such excellent information. Keep up the good work and thanks for sharing your information.
    https://www.vcubesoftsolutions.com/all-courses/
    java full stack course in Hyderabad
    Python full stack course in Hyderabad
    Testing tools course in Hyderabad
    Power Bi course in Hyderabad
    Devops course in Hyderabad

    ReplyDelete
  60. I'm sorry for acting like I want to jump on you. I just like taking the piss out of uplifting, viral internet things. our sclinbio.com

    ReplyDelete
  61. A React course is a training program that teaches you how to use React, a JavaScript library for building user interfaces. React is one of the most popular JavaScript libraries in the world, and it is used by many large companies, such as Facebook, Airbnb, and Netflix.

    A React course typically covers the following topics:

    The basics of React, including components, state, and props
    Advanced React topics, such as routing, Redux, and testing
    How to build real-world applications with React
    The best React courses will be well-structured, engaging, and easy to follow. They will also provide you with plenty of opportunities to practice what you learn.
    reactgeeks

    ReplyDelete
  62. I must thank you for thfe efforts you’ve put in writing this blog.

    ReplyDelete
  63. I’m truly enjoying the design and layout of your blog.

    ReplyDelete
  64. Nice to be visiting your blog again. it has been months for me.

    ReplyDelete
  65. Well this article that i’ve been waited for so long.

    ReplyDelete
  66. I must thank you for the efforts you’ve put in this blog. Awesome!

    ReplyDelete
  67. This is really helpful post and very informative there is no doubt about it.

    ReplyDelete
  68. I’m glad that you simply shared this helpful info with us.

    ReplyDelete
  69. it was really great for me – I was looking for such a thing

    ReplyDelete
  70. I am really happy to say it’s an interesting post to read .

    ReplyDelete
  71. I am looking for some good blog sites for studying.

    ReplyDelete
  72. Very great post. I just came across your weblog

    ReplyDelete
  73. There is perceptibly a lot to identify about this.

    ReplyDelete
  74. I found your website perfect for my needs. It contains wonderful and helpful posts.

    ReplyDelete
  75. Keep up the good work!. Thank you for this wonderful Article!

    ReplyDelete
  76. Thanks for sharing this awesome content, it would be helpful.

    ReplyDelete
  77. Guys just sharing, I’ve found this interesting! Check it out!

    ReplyDelete
  78. A Highly informative and easy-to-follow read

    ReplyDelete

Popular Posts