title: Send a message to and get back a response from a message driven bean
body: <p>I'm trying to have a response back to a message driven bean but for an unknown reason I am not able to make work the communication correctly. </p>
  
  <p>here is it the stateful bean. It send an object message and after create a temporary queue where receive the response.</p>
  
  <pre><code>@Stateful
  public class BookingManagerBean implements BookingManagerBeanInterface
  {
  
      @Inject
      @JMSConnectionFactory("jms/reservationProcessorQueueFactory")
      private JMSContext context;
  
      @Resource(mappedName = "jms/bookingProcessorQueueReceiver")
      private Queue bookingProcessorQueueReceiver;
  
      private Queue tempQueue;
  
      private JMSProducer messageProducer = null;
      private JMSConsumer messageConsumer = null;
  
      private String id_reservation = null;
  
      private Map&lt;String,Object&gt; map;
  
      @Override
      public String purchase()
      {                         
  
          try
          {
              sendMessageToBookingProcessorBean(object1, object2); // invia il messaggio contenente la prenotazione e il numero di punti utilizzati
  
              receiveMessageFromBookingProcessorBean(); // ricevi il messaggio dal MDB
          }
          catch(JMSException jmse)
          {
              System.err.println("An error occured " + jmse.toString());
              return (id_reservation);
          }
  
          return id_reservation;
      }
  
      private void sendMessageToBookingProcessorBean(Object object1, int object2) throws JMSException
      {                                  
          messageProducer = context.createProducer();
  
          messageProducer.send(bookingProcessorQueueReceiver,createMessageForBookingProcessorBean(object1, object2));
      }
  
      private Message createMessageForBookingProcessorBean(Object object1, int object2) throws JMSException
      {              
          ObjectMessage msg = context.createObjectMessage();
  
          tempQueue = context.createTemporaryQueue(); //create la queue temporanea dove sarà inviata la risposta
          messageConsumer = context.createConsumer(tempQueue);
  
          msg.setJMSReplyTo(tempQueue); 
  
          map = new HashMap&lt;&gt;();
  
          map.put("object1", object1);
          map.put("object2", object2);
  
          msg.setObject((Serializable) map);
  
          return msg;
      }
  
      private void receiveMessageFromBookingProcessorBean() throws JMSException
      {                
          Message msg = messageConsumer.receive();
  
          if(msg instanceof TextMessage)
          {
              TextMessage string = (TextMessage)msg;
  
              this.id_reservation = string.getText();
          }                
      }
  }
  </code></pre>
  
  <p>Here is it the message driven bean</p>
  
  <pre><code>@MessageDriven(mappedName = "jms/bookingProcessorQueueReceiver", 
                 activationConfig = {@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
                                     @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
  })
  public class BookingProcessorBean implements MessageListener
  {   
      @PersistenceContext
      private EntityManager em;
  
      @Inject
      @JMSConnectionFactory("jms/reservationProcessorQueueFactory")
      private JMSContext context;
  
  
  
      @Override
      public void onMessage(Message message)
      {                                  
          try
          {       
              ObjectMessage om = (ObjectMessage) message;
  
              map = (HashMap&lt;String,Object&gt;) om.getObject();
  
  
              System.out.println("Processing reservation...");
  
  
              sendIdReversationToBookingManagerBean(om.getJMSReplyTo(), "message response"); //prende la destinazione temporanea ed il messaggio
          }
          catch(UnsupportedEncodingException uee)
          {
              System.err.println("An error occured during the sending of the confirmation mail to " + reserv.getUsername().getEmail());
          }
          catch(MessagingException me)
          {
              System.err.println("An error occured during the sending of the email to " + reserv.getUsername().getEmail());
          }
          catch(JMSException e)
          {
              System.err.println("An error occured during the processing of the booking " + reserv.getId());
          }
      }
  
  
      private Message createMessageForBookingManagerBean(String message) throws JMSException
      {
          TextMessage msg = context.createTextMessage();
  
          msg.setText(message);
  
          return msg;
      }
  
      private void sendIdReversationToBookingManagerBean(Destination tempReceiverDestination, String message) throws JMSException
      {
          JMSProducer messageProducer = context.createProducer();
  
          messageProducer.send(tempReceiverDestination, createMessageForBookingManagerBean(id));
      }
  }
  </code></pre>
  
  <p>I have tried to make some debug and I have noticed the program stuck in receive method. I'm pretty sure something doesn't work. May you help me?</p>