-
1. Re: Using the same Queue to send different data types
ataylor Sep 26, 2012 4:54 AM (in response to halfpad)it makes no difference which message type you use its all handled the same, persisted as bytes, so you can send them all to the same queue. Bear in mind tho that using Object Message will slow things down as its dependant on java serialization.
-
2. Re: Using the same Queue to send different data types
halfpad Sep 26, 2012 5:17 AM (in response to ataylor)Hi Andy
Thank you for your reply.
I was hoping to find out why the design pattern exists, and what alternatives there are for my situation where I don't want to have that many queues.
I'm using the BodyBuffer to write the Bytes of the Object I'm sending. The problem I was having was when receiving the message and constructing an Object from the ByteArrayInputStream, I did not want to have a bunch of "instanceof" checks to dermine which Object I received. But I assume the only alternative is to have separate queues for each object type?
-
3. Re: Using the same Queue to send different data types
ataylor Sep 26, 2012 5:39 AM (in response to halfpad)I was hoping to find out why the design pattern exists, and what alternatives there are for my situation where I don't want to have that many queues.
you dont have to have that many queues, you can use 1
I'm using the BodyBuffer to write the Bytes of the Object I'm sending. The problem I was having was when receiving the message and constructing an Object from the ByteArrayInputStream, I did not want to have a bunch of "instanceof" checks to dermine which Object I received. But I assume the only alternative is to have separate queues for each object type?
well thats really a design choice for your application, if your application is sending lots of different types of message being handled by the same consumer maybe your design is flawed
-
4. Re: Using the same Queue to send different data types
jbertram Sep 26, 2012 10:29 AM (in response to halfpad)I assume you're talking about the "Datatype Channel" pattern outlined here. This pattern is addressing the question, "How can the application send a data item such that the receiver will know how to process it?" Using a typed channel is one way to do it. Using a bunch of instanceof checks would be another way to do it. Why are you opposed to a bunch of instanceof checks? The expressions are simple and readable.
-
5. Re: Using the same Queue to send different data types
halfpad Sep 27, 2012 1:52 AM (in response to jbertram)Thank you for your reply Justin.
You are indeed correct, the "Datatype Channel" was the one I was looking at.
I must confess that I was following the all-instanceof-checks-are-bad crowd, and was hoping someone would suggest an alternative pattern.
Until someone suggests another solution, I'll stick to the "instanceOf" or "getClass" options.
-
6. Re: Using the same Queue to send different data types
jbertram Sep 27, 2012 10:12 AM (in response to halfpad)If you really wanted to avoid the instanceof checks then you could establish a simple property protocol between the sender and consumer. For example, set a string property named "type" on each message sent and assign it a value which the consumer can then take and use to cast the object in the message.
-
7. Re: Using the same Queue to send different data types
ataylor Sep 27, 2012 10:19 AM (in response to jbertram)If you really wanted to avoid the instanceof checks then you could establish a simple property protocol between the sender and consumer. For example, set a string property named "type" on each message sent and assign it a value which the consumer can then take and use to cast the object in the message.
Or even better, filter on the property and have a consumer deal with each type of message (which is how it should be done, you wouldnt write a method that did 10 different things and have an if statement you would abstract it out)