Пример #1
0
    public IotHubMessageResult execute(Message msg, Object context) {
      Counter counter = (Counter) context;
      System.out.println(
          "Received message "
              + counter.toString()
              + " with content: "
              + new String(msg.getBytes(), Message.DEFAULT_IOTHUB_MESSAGE_CHARSET));

      int switchVal = counter.get() % 3;
      IotHubMessageResult res;
      switch (switchVal) {
        case 0:
          res = IotHubMessageResult.COMPLETE;
          break;
        case 1:
          res = IotHubMessageResult.ABANDON;
          break;
        case 2:
          res = IotHubMessageResult.REJECT;
          break;
        default:
          // should never happen.
          throw new IllegalStateException("Invalid message result specified.");
      }

      System.out.println("Responding to message " + counter.toString() + " with " + res.name());

      counter.increment();

      return res;
    }
Пример #2
0
    public IotHubMessageResult execute(Message msg, Object context) {
      Counter counter = (Counter) context;
      System.out.println(
          "Received message "
              + counter.toString()
              + " with content: "
              + new String(msg.getBytes(), Message.DEFAULT_IOTHUB_MESSAGE_CHARSET));

      counter.increment();

      return IotHubMessageResult.COMPLETE;
    }