11 Replies Latest reply on Nov 24, 2009 12:50 PM by Tim Fox

    Do we really need ClientProducer?

    Tim Fox Master

      I was thinking it might simplify the client API significantly if we removed it and sent messages like this instead:

      
      ClientSession session = sf.createSession(...);
      
      ClientMessage message = session.createMessage(false); // non durable
      
      message.setDestination("my_address");
      
      message.send();
      
      


      wdyt?

        • 1. Re: Do we really need ClientProducer?
          Jeff Mesnil Master

          message.send() looks akward...

          why not put the send() method on the session instead?

          ClientSession session = sf.createSession(...);
          ClientMessage message = session.createMessage(false);
          message.setDestination("my_address");
          session.send(message);
          




          • 2. Re: Do we really need ClientProducer?
            Tim Fox Master

             

            "jmesnil" wrote:
            message.send() looks akward...

            why not put the send() method on the session instead?

            ClientSession session = sf.createSession(...);
            ClientMessage message = session.createMessage(false);
            message.setDestination("my_address");
            session.send(message);
            




            We could do either, but I prefer message.send(), since the user does not have to pass around references to both the session and the message, they just need the reference to the message.

            • 3. Re: Do we really need ClientProducer?
              Tim Fox Master

              e.g.

              
              ClientMessage message1 = session1.createClientMessage();
              ClientMessage message2 = session2.createClientMessage();
              ClientMessage message3 = session3.createClientMessage();
              
              sendMessages(message1, message2, message3);
              
              ...
              
              void sendMessages(ClientMessage... msgs)
              {
               for (ClientMessage msg: msgs)
               {
               msg.send();
               }
              }
              


              It also prevents you sending a message on a session that it was not created on, which can cause weird bugs.


              • 4. Re: Do we really need ClientProducer?
                Jeff Mesnil Master

                ClientMessage is also the object received by the ClientConsumer.

                I'd find counter-intuitive to have a send() message on a message I've received. What does it mean to call send() on this message?
                Putting send() on the session make the API less confusing.

                • 5. Re: Do we really need ClientProducer?
                  Tim Fox Master

                   

                  "jmesnil" wrote:
                  ClientMessage is also the object received by the ClientConsumer.

                  I'd find counter-intuitive to have a send() message on a message I've received. What does it mean to call send() on this message?
                  Putting send() on the session make the API less confusing.


                  Why is it counterintuitive? You can resend messages after sending, e.g.

                  
                  ClientMessage message = consumer.receive();
                  
                  message.setDestination("forward_adress");
                  
                  message.send();
                  
                  


                  This seems very intuitive to me.

                  • 6. Re: Do we really need ClientProducer?
                    Clebert Suconic Master

                    +1 to Jeff.. If we remove the ClientProducer I would prefer Session.send(....)

                    Besides... how would someone resend a message receiving from a consumer, and send it to another session?

                    e.g

                    ClientConsumer cons1 = sessionServer1.createConsumer(.....);

                    ClientMessage msgFromServer1 = cons1.receive(....);


                    sessionServer2.send(msgFromServer1);

                    • 7. Re: Do we really need ClientProducer?
                      Clebert Suconic Master

                      If you remove the ClientProducer,

                      How would you agregate and guarantee producer rate and flow control?

                      Those things are controlled at the producer's level.

                      • 8. Re: Do we really need ClientProducer?
                        Tim Fox Master

                         

                        "clebert.suconic@jboss.com" wrote:
                        +1 to Jeff.. If we remove the ClientProducer I would prefer Session.send(....)

                        Besides... how would someone resend a message receiving from a consumer, and send it to another session?


                        That's illegal anyway.

                        You can only send a message on the session it was created from.


                        • 9. Re: Do we really need ClientProducer?
                          Clebert Suconic Master

                          Huh?

                          We do that all the time with the bridge...

                          It's a common thing on JMS also?


                          public class TestSend extends ServiceTestBase
                          {
                          
                           public void test() throws Exception
                           {
                           HornetQServer server = createServer(false);
                          
                           server.start();
                          
                           ClientSessionFactory factory = createInVMFactory();
                           ClientSession session1 = factory.createSession();
                          
                           session1.createQueue("q", "q");
                          
                           ClientProducer prod1 = session1.createProducer("q");
                          
                           ClientMessage msg = session1.createClientMessage(true);
                          
                           msg.acknowledge();
                          
                           assertNotNull(msg);
                          
                           prod1.send(msg);
                          
                           session1.start();
                          
                           ClientConsumer cons = session1.createConsumer("q");
                          
                           ClientMessage msgreceived = cons.receive(10000);
                           assertNotNull(msgreceived);
                           msgreceived.acknowledge();
                          
                           ClientSession session2 = factory.createSession();
                          
                           ClientProducer prod2 = session1.createProducer("q");
                          
                           prod2.send(msgreceived);
                          
                          
                           session1.close();
                           session2.close();
                          
                           server.stop();
                           }
                          
                          }
                          
                          


                          • 10. Re: Do we really need ClientProducer?
                            Tim Fox Master

                             

                            "clebert.suconic@jboss.com" wrote:
                            Huh?

                            We do that all the time with the bridge...

                            It's a common thing on JMS also?


                            I think the phrase "duh" would be appropriate right now ;)

                            • 11. Re: Do we really need ClientProducer?
                              Tim Fox Master

                               

                              "clebert.suconic@jboss.com" wrote:
                              If you remove the ClientProducer,

                              How would you agregate and guarantee producer rate and flow control?

                              Those things are controlled at the producer's level.


                              Actually, they're on the session level.