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

How to write the products in a cart to an MDB

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am a newbie trying to learn JMS using a shopping cart web application.Here, I have stored the products in a user's cart in session context. On checkout,I want to write this to a Message driven bean's onMessage() method from where these products will be persisted to the database. Should I write the products in the cart as a comma separated file and send it to the MDB's onMessage()? Could you please help me? If so, how do I write the products as a comma separated file. I have Product name, description, price and quantity which have to be stored to the database.
Thanks in advance
Vidya
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This sounds unnecessarily complex. Why create a file and then send the file contents? Why not use the JMS API to send the shopping cart contents directly?

In addition, using JMS as a communications channel between the web layer and the EJB layer means that you can't give the user feedback that the checkout succeeded - JMS message handling is asynchronous, and even if it happens quickly, you won't have feedback on whether it succeeded by the time the JMS call returns (at which point you presumably generate the response HTML for the user).

Is that acceptable in your scenario, or are you handling this some way?
 
Vidya Moorthy
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How could I use the JMS API to send the contents directly? Could I use the send message to put the shopping cart contents as a session attribute and then send it to the queue. Since I am completely new, I am trying really hard to figure this out! Please explain it to me!
Thanks,
Vidya
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, this doesn't sound like a good use case for a message queue. The user has an expectation to get rapid feedback of whether or not the order has been processed. So there should be synchronous feedback - the web tier calls into the business tier, and gets back a confirmation or an error message, which is then displayed to the user.

Message queues, on the other hand, are used to decouple two components. The receiver retrieves messages and processes them at its convenience. That could be milliseconds or hours after the message is sent. Plus, there is no direct feedback. The retrieving side might in turn send a message to the original sending site with feedback, but all this happens asynchronously. A workflow that involves a human being standing by for feedback should not use message queues.

There's a JMS tutorial here.
[ June 11, 2008: Message edited by: Ulf Dittmer ]
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have much more important things to do than getting concerned about JMS. For instance, you need to write a class which has fields for the data you are capturing. This must be Serializable for a remote client. You need to instantiate the class, populate the object, send it to a session EJB, extract the data from the object, load the DB. (Have you written the SQL?)You will need to sort out transaction handling.

Later, if you insist, you can always replace the session EJB with a MDB.
 
Vidya Moorthy
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the feedback. I have written the Products class as a serializable one so that it could be saved. It has those as instance variables and the object has been created by setter methods. I have never used session beans. I will be learning this tutorial pretty soon. The DB has values for the records. When I bypass the JMS, the Cart's contents are inserted into a DB successfully. Technically, this idea is flawed I understand. But for the sake of implementing my JMS knowledge, if I have to use an MDB to save the cart products as a message. How do I do that? Please let me know.
Thanks
Vidya
 
Wanna see my flashlight? How about this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic