Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MapMessage vs HashMap in setObjectMessage

 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to pass data consisting of name,value pairs from a JMS Publisher to an MDB. I am not sure which option would be better....

1. MapMessage or
2. setObjectMessage() using the HashMap object..
Note: HashMap implements Serializable interface, so I reckon it might be OK to be used in setObjectMessage.
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vishwa,

In my opinion MapMessage should be the best choice, if you intend to send collections of primitive data type (or their wrappers). First because MapMessages suppose to perform better than ObjectMessage, which adds the serialization extra-cost when passing data across application boundaries. Secondly adding new name-value pairs to the MapMessage is not going to break your code. Another drawback of using ObjectMessage is that it relies on the sender and receiver having the same exact version of the class and sometimes this might be a pain in the b� The only two reasons I�m aware about that should convince one to use the ObjectMessage are to have an object-oriented approach for sending/receiving messages. In your case though, since the object itself is a HashMap, you�re kind of loosing this feature. Another limitation of MapMessage is that you cannot send any type of data, but only primitive and their Java wrappers.
Regards.
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Valentin.
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're very welcome Vishwa
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic