Object messages are too hard to work with



  • Given this object:

       class TheObject implements Serializable {
    // Nothing but Serializable objects contained within the class
    }

    I wrote something to put this on a queue to another system:

        TheObject theObject = new TheObject(...);
    Message message = session.createObjectMessage(theObject);
    message.setJMSCorrelationID(decimalFormat.format(++correlationId));
    producer = session.createProducer(theQueue);
    producer.setTimeToLive(24*3600*1000);
    producer.send(message);


    and told the developer on the other team that all he needed to do upon receipt of the message was:

       import path.to.TheObject;
    ...
    TheObject theObject = (TheObject) queueMessage.getObject();
    // use theObject normally

    Even though we're all working on the same version of the JVM, and will never actually have divergent versions of the object, he complained that Object messages are too hard to work with.




  • Clue bat time, I'd say.



  • @snoofle said:

    Given this object:
       class TheObject implements Serializable {
    // Nothing but Serializable objects contained within the class
    }

    I wrote something to put this on a queue to another system:

        TheObject theObject = new TheObject(...);
    Message message = session.createObjectMessage(theObject);
    message.setJMSCorrelationID(decimalFormat.format(++correlationId));
    producer = session.createProducer(theQueue);
    producer.setTimeToLive(24*3600*1000);
    producer.send(message);


    and told the developer on the other team that all he needed to do upon receipt of the message was:

       import path.to.TheObject;
    ...
    TheObject theObject = (TheObject) queueMessage.getObject();
    // use theObject normally

    Even though we're all working on the same version of the JVM, and will never actually have divergent versions of the object, he complained that Object messages are too hard to work with.


    He's right ... you need to make a type-safe Queue with generics:

        TheObject theObject = new TheObject(...);
    Message<TheObject> message = session.createObjectMessage(theObject);
    message.setJMSCorrelationID(decimalFormat.format(++correlationId));
    producer = session.createProducer(theQueue);
    producer.setTimeToLive(24*3600*1000);
    producer.send(message);

    Now you don't need the cast on the receiving side:

       import path.to.TheObject;
    ...
    TheObject theObject = queueMessage.getObject();
    // use theObject normally


  • @snoofle said:

    Object messages are too hard to work with
    "So are you, but you don't hear me complaining about it"



  • @DOA said:

    "So are you, but you don't hear me complaining about it"




    Ha! Going to have to remember that the next time my project lead says something is too difficult to use correctly.



  • @snoofle said:

    [snip]
    he complained that Object messages are too hard to work with.



    "If it were easy, the customers would do it."



  • @zelmak said:

    He's right ... you need to make a type-safe Queue with generics:

        TheObject theObject = new TheObject(...);
        Message<TheObject> message = session.createObjectMessage(theObject);
        message.setJMSCorrelationID(decimalFormat.format(++correlationId));
        producer = session.createProducer(theQueue);
        producer.setTimeToLive(24*3600*1000);
        producer.send(message);

    Now you don't need the cast on the receiving side:

       import path.to.TheObject;
       ...
       TheObject theObject = queueMessage.getObject();
       // use theObject normally

    +1


  • @DOA said:

    @snoofle said:
    Object messages are too hard to work with
    "So are you, but you don't hear me complaining about it"
     

    That.

    Or some dismissive comment around "Oh, you're the junior programmer, right? Where do I find the experienced one? [s]he should be mentoring you..."



  •  Or as a Silicon Valley Company that acquired us once said.....

    "You can't do that,  the customers will see it and want it everywhere!"

    I started drawing up my exit strategy,

     


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.