예제 #1
0
  public void onMessage(Message message) {

    try {
      boolean accepted = false;

      // Get the data from the message
      MapMessage msg = (MapMessage) message;
      double salary = msg.getDouble("Salary");
      double loanAmt = msg.getDouble("LoanAmount");

      // Determine whether to accept or decline the loan
      if (loanAmt < 200000) {
        accepted = (salary / loanAmt) > .25;
      } else {
        accepted = (salary / loanAmt) > .33;
      }
      System.out.println(
          ""
              + "Percent = "
              + (salary / loanAmt)
              + ", loan is "
              + (accepted ? "Accepted!" : "Declined"));

      // Send the results back to the borrower
      TextMessage tmsg = qSession.createTextMessage();
      tmsg.setText(accepted ? "Accepted!" : "Declined");

      // correlation
      tmsg.setJMSCorrelationID(message.getJMSMessageID());

      // Create the sender and send the message
      qSender = qSession.createSender((Queue) message.getJMSReplyTo());
      qSender.send(tmsg);

      System.out.println("\nWaiting for loan requests...");

    } catch (JMSException jmse) {
      jmse.printStackTrace();
      System.exit(1);
    } catch (Exception jmse) {
      jmse.printStackTrace();
      System.exit(1);
    }
  }
예제 #2
0
파일: Recruiter.java 프로젝트: saquil/JMS
  public void onMessage(Message message) {

    try {
      boolean accepted = false;

      // Get the data from the message
      MapMessage msg = (MapMessage) message;
      double salary = msg.getDouble("Salary");
      double expAmt = msg.getDouble("Years’ experience");

      // Determine whether to accept or decline the loan
      if (expAmt < 200000) {
        accepted = (salary / expAmt) > .25;
      } else {
        accepted = (salary / expAmt) > .33;
      }
      if (salary <= 32000) {
        accepted = true;
      } else {
        if (expAmt == 0) accepted = false;
        else accepted = ((double) (expAmt - 32000) / expAmt) < 3000.;
      }
      System.out.println(" Salary proposal is " + (accepted ? "Accepted!" : "Declined"));

      // Send the results back to the borrower
      TextMessage tmsg = qSession.createTextMessage();
      tmsg.setText(accepted ? "Accepted!" : "Declined");
      tmsg.setJMSCorrelationID(message.getJMSMessageID());

      // Create the sender and send the message
      QueueSender qSender = qSession.createSender((Queue) message.getJMSReplyTo());
      qSender.send(tmsg);

      System.out.println("\nWaiting for salary requests...");

    } catch (JMSException jmse) {
      jmse.printStackTrace();
      System.exit(1);
    } catch (Exception jmse) {
      jmse.printStackTrace();
      System.exit(1);
    }
  }