1 2 Previous Next 20 Replies Latest reply on Nov 15, 2012 6:39 AM by gaohoward

    invalid type code

    akhil08

      Hi,

       

      I noticed the following exception when onMessage call back is triggered on consumer.

       

      javax.jms.JMSException: invalid type code: 32

                at java.io.ObjectInputStream$BlockDataInputStream.readBlockHeader(Unknown Source)

                at java.io.ObjectInputStream$BlockDataInputStream.refill(Unknown Source)

                at java.io.ObjectInputStream$BlockDataInputStream.read(Unknown Source)

                at java.io.DataInputStream.readInt(Unknown Source)

                at java.io.ObjectInputStream$BlockDataInputStream.readInt(Unknown Source)

                at java.io.ObjectInputStream.readInt(Unknown Source)

                at java.util.HashMap.readObject(Unknown Source)

                at sun.reflect.GeneratedMethodAccessor8.invoke(Unknown Source)

                at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

                at java.lang.reflect.Method.invoke(Unknown Source)

                at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)

                at java.io.ObjectInputStream.readSerialData(Unknown Source)

                at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)

                at java.io.ObjectInputStream.readObject0(Unknown Source)

                at java.io.ObjectInputStream.defaultReadFields(Unknown Source)

                at java.io.ObjectInputStream.readSerialData(Unknown Source)

                at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)

                at java.io.ObjectInputStream.readObject0(Unknown Source)

                at java.io.ObjectInputStream.defaultReadFields(Unknown Source)

                at java.io.ObjectInputStream.readSerialData(Unknown Source)

                at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)

                at java.io.ObjectInputStream.readObject0(Unknown Source)

                at java.io.ObjectInputStream.readObject(Unknown Source)

                at java.util.ArrayList.readObject(Unknown Source)

                at sun.reflect.GeneratedMethodAccessor17.invoke(Unknown Source)

                at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

                at java.lang.reflect.Method.invoke(Unknown Source)

                at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)

                at java.io.ObjectInputStream.readSerialData(Unknown Source)

                at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)

                at java.io.ObjectInputStream.readObject0(Unknown Source)

                at java.io.ObjectInputStream.defaultReadFields(Unknown Source)

                at java.io.ObjectInputStream.readSerialData(Unknown Source)

                at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)

                at java.io.ObjectInputStream.readObject0(Unknown Source)

                at java.io.ObjectInputStream.readArray(Unknown Source)

                at java.io.ObjectInputStream.readObject0(Unknown Source)

                at java.io.ObjectInputStream.defaultReadFields(Unknown Source)

                at java.io.ObjectInputStream.readSerialData(Unknown Source)

                at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)

                at java.io.ObjectInputStream.readObject0(Unknown Source)

                at java.io.ObjectInputStream.readObject(Unknown Source)

                at org.hornetq.jms.client.HornetQObjectMessage.getObject(HornetQObjectMessage.java:158)

      at com.consumer.MessageConsumer.onMessage(MessageConsumer.java:100)

                at org.hornetq.jms.client.JMSMessageListenerWrapper.onMessage(JMSMessageListenerWrapper.java:91)

                at org.hornetq.core.client.impl.ClientConsumerImpl.callOnMessage(ClientConsumerImpl.java:953)

                at org.hornetq.core.client.impl.ClientConsumerImpl.access$200(ClientConsumerImpl.java:46)

                at org.hornetq.core.client.impl.ClientConsumerImpl$Runner.run(ClientConsumerImpl.java:1082)

                at org.hornetq.utils.OrderedExecutorFactory$OrderedExecutor$1.run(OrderedExecutorFactory.java:100)

                at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)

                at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

                at java.lang.Thread.run(Unknown Source)

       

       

       

      Here is the logic of onMessage() in MessageConsumer

       

      public void onMessage( javax.jms.Message msg) {

       

           ObjectMessage message = (ObjectMessage) msg;

       

            message.getObject();   // Error thrown at this call

       

      }

       

       

      It only happened for one message. All other messages were consumed properly. What does this exception mean? Can someone guide me in the right direction here?

        • 1. Re: invalid type code
          akhil08

          Looks like the issue occured during de-serialization of object message. But I don't understand why only for this message ? There are many messages with same object type that were consumed by the client succesfully. What does " invalid type code: 32" mean?

          • 2. Re: invalid type code
            gaohoward

            What's your object class looks like? I believe there is some serialization issue in the object's code. Take a look at this:

             

            http://stackoverflow.com/questions/9217010/serialisation-in-java-invalid-type-code-00

            • 3. Re: invalid type code
              akhil08

              Thanks Yong for your response. As I already mentioned all the objects are identical and exception occured only to one message . So this makes me belive that it is a serialization issue. Also when the message is published by producer around the same time i see the following warning .

               

              WARN  [ServerSessionImpl] Replacing incomplete LargeMessage with ID=68767456755

               

              I believe this is related to message that consumer failed to consume( i,e exception when onMessage call back is triggered on consumer.) . Can you tell me what that warning message is about. Could that be related and if it is how?

              • 4. Re: invalid type code
                gaohoward

                The log means at the moment there is already an unfinished large message with the session.

                 

                I'm not sure about how you get this. Did you share a session among threads when you do message sending?

                • 5. Re: invalid type code
                  akhil08

                  Thank you for clarifying. Yes session is shared across multiple threads and fixed the code to not share it.  So do you mean that WARN  [ServerSessionImpl] Replacing incomplete LargeMessage with ID=68767456755 is the cause for javax.jms.JMSException: invalid type code: 32 in my case? If so can you elaborate a bit. Your assistance on this is much appreciated.

                  • 6. Re: invalid type code
                    gaohoward

                    I don't have the exact information to say how this 'invalid type code' is caused. However the warning messages clearly suggests that a session is used concurrently and it causes the session to abandon the current unfinished sending of a large message and go for another. This sure will break the normal working of the message sending.

                    • 7. Re: invalid type code
                      gaohoward

                      by the way please use user forum for further question/issues. This forum is for development related discussions.

                      • 8. Re: invalid type code
                        akhil08

                        Thanks a lot Yong for your assistance on this. Sure i will use user forum for any questions in future. Before i close this i need some clarification , few of them are trivial though.

                         

                        * lets say i have two threads(producers), both producing to same topic at the same time. I understand that i need two different sessions & corresponding publishers in this case. Am I correct?

                         

                        Thread1

                        =====

                        ObjectMessage message =  session1.createObjectMessage();

                        session1.createPublisher("Topic1").publish(message,........);

                         

                        Thread2

                        ======

                        ObjectMessage message =  session2.createObjectMessage();

                        session2.createPublisher("Topic1").publish(message,........);

                         

                         

                        * If thread1 publishes first and thread2 publishes next using different sessions, is it gauranteed that message published by thread1 is delivered first (or) order is not gauranteed eventhough thread1 published first as I am using separate sessions for each thread.

                         

                         

                        *Lets say messages are published in a loop in Thread1 as below

                         

                        \\session1, publiher1 created in advance

                         

                        loop{

                         

                        ObjectMessage message =  session1.createObjectMessage();

                        publiher1.publish(message,........);

                         

                        }

                         

                        If 10 messages are published using loop using same session, what exactly is behavior ? Does each session has it's own queue where it hold all the messages processing/delivering one at a time. I want to know how exactly session behaves in this scenario.

                         

                        Your assistance on the above questions would be much appreciated.

                         

                        Thanks

                        • 9. Re: invalid type code
                          gaohoward

                          * lets say i have two threads(producers), both producing to same topic at the same time. I understand that i need two different sessions & corresponding publishers in this case. Am I correct?

                           

                          Thread1

                          =====

                          ObjectMessage message =  session1.createObjectMessage();

                          session1.createPublisher("Topic1").publish(message,........);

                           

                          Thread2

                          ======

                          ObjectMessage message =  session2.createObjectMessage();

                          session2.createPublisher("Topic1").publish(message,........);

                           

                          That's correct.

                           

                          * If thread1 publishes first and thread2 publishes next using different sessions, is it gauranteed that message published by thread1 is delivered first (or) order is not gauranteed eventhough thread1 published first as I am using separate sessions for each thread.

                          The order is not guaranteed. You can't rely on this. If you want strict order, you need take a look at 'message group' feature of hornetq.

                           

                           

                          *Lets say messages are published in a loop in Thread1 as below

                           

                          \\session1, publiher1 created in advance

                           

                          loop{

                           

                          ObjectMessage message =  session1.createObjectMessage();

                          publiher1.publish(message,........);

                           

                          }

                           

                          If 10 messages are published using loop using same session, what exactly is behavior ? Does each session has it's own queue where it hold all the messages processing/delivering one at a time. I want to know how exactly session behaves in this scenario.

                           

                          Sessions do not own queues. The 10 messages will be sent to the server and then routed to their target queues/topics. Then the messages are delivered to the consumers. The session process the sending/receiving of messages serially, i.e. one message after another.

                          • 10. Re: invalid type code
                            akhil08

                            * If thread1 publishes first and thread2 publishes next using different sessions, is it gauranteed that message published by thread1 is delivered first (or) order is not gauranteed eventhough thread1 published first as I am using separate sessions for each thread.

                            The order is not guaranteed. You can't rely on this. If you want strict order, you need take a look at 'message group' feature of hornetq.

                             

                            I didn't quite get this. if thread1 publishes using session1 ,from the documentation I understand that message is already delivered to server. If thread2 publishes later using session2 how can the message published by thread2 be delivered first(I am not sure about the implementation) before the message published by thread1. Can you elaborate a bit on this.

                            • 11. Re: invalid type code
                              gaohoward

                              There are situations that may affect the order. For example if messages have different priorities. Messages with higher priorities may be delivered before those with lower priorities, even though the lower ones arrives at the server first. Another case is that if during the receiving the client application crashed, all un-acked messages will be cancelled back to server for re-delivery, in this case you can't assume the message order will be kept.

                              • 12. Re: invalid type code
                                akhil08

                                There are situations that may affect the order. For example if messages have different priorities. Messages with higher priorities may be delivered before those with lower priorities, even though the lower ones arrives at the server first.

                                 

                                  -> Isn't this same even if I have single session? Also in my case i don't set any priority on messages in that case i assume all messages have same priority.


                                Another case is that if during the receiving the client application crashed, all un-acked messages will be cancelled back to server for re-delivery, in this case you can't assume the message order will be kept.

                                 

                                -> Again i don't see how this is not the case even if i use single session. According to your explaination even if i am publishing messages using single session, if client application crashed while receiveing messages un-acked messages will be cancelled back to server and the message order is not kept as per your statement.

                                 

                                My Question was "If thread1 publishes first and thread2 publishes next using different sessions, is it gauranteed that message published by thread1 is delivered first (or) order is not gauranteed eventhough thread1 published first as I am using separate sessions for each thread".   The above cases which you explained holds true even if there is single session.


                                • 13. Re: invalid type code
                                  gaohoward

                                  Yes it's true with single session too. Maybe I didn't understand your question well. Using separate threads for sending, you can't guarantee which thread will send message first and which second. Each thread works independently unless you synchronize them, but then what's the use of two threads? Can you explain more about why you want two threads while the order is of your concern?

                                   

                                  Howard

                                  • 14. Re: invalid type code
                                    akhil08

                                    Here is the exact situation (Thread1 and Thread2 uses different sessions)

                                    =====================================================

                                     

                                    Thread1: In this thread we 1) create an order(message) 2) publish order(message) to other clients (using jms) and then 3) route order to exchange.

                                    Once order is routed to exchange, application starts receiving executions back.

                                     

                                    Thread2: All the executions(messages) are published(jms) using this thread.

                                     

                                    While executions are being published for previous order using Thread2, clients can send out new orders using Thread1 which involves publishing

                                    (step2 of  Thread1 ). In order to over come threading issue with sessions I am using two sessions here.

                                     

                                    The sequence is only important between an order(message) and it's executions. Is Order(message) guaranteed to be delivered to client

                                    before it's corresponding executions as I am using two sessions here? Note that we receive executions(Thread2) for corresponding order

                                    only after routing order to exchange by which time order(message) is already published using Thread1.

                                    1 2 Previous Next