code: public String receiveTextMessageFromDestinationWithTimeout(final String destinationName, final int timeout) {
  
  
          if (!this.isConnected()) {
              throw new JmsNotConnectedException("Not connected");
          }
          MessageConsumer consumer = getConsumer(destinationName);
          TextMessage message;
          try {
              if (timeout == 0) {
                  message = (TextMessage) consumer.receiveNoWait();
              } else {
                  message = (TextMessage) consumer.receive(timeout);
              }
              if (message != null) {
  
                  if (acknowledgeMode == Session.CLIENT_ACKNOWLEDGE) {
                      message.acknowledge();
                  }
                  return message.getText();
              } else {
                  return null;
              }
          } catch (JMSException e) {
              throw new JmsException("Unable to receive message from " + destinationName, e);
          }
      }
docs: Receive a message from  destination with timeout.
  
  @param destinationName destinationName
  @param timeout         timeout
  @return message