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; } }
public IotHubMessageResult execute(Message msg, Object context) { Counter counter = (Counter) context; System.out.println( "Device Client " + msg.getIotHubConnectionString().getDeviceId() + " received message " + counter.toString() + " with content: " + new String(msg.getBytes(), Message.DEFAULT_IOTHUB_MESSAGE_CHARSET)); for (MessageProperty messageProperty : msg.getProperties()) { System.out.println(messageProperty.getName() + " : " + messageProperty.getValue()); } IotHubMessageResult res = IotHubMessageResult.COMPLETE; System.out.println( "Responding to message " + counter.toString() + " with " + res.name()); counter.increment(); return res; } }
break; default: logger.LogError("Invalid IoT Hub message result (%s), method name is %s ", result.name(), logger.getMethodName()); return false;
+ " with " + res.name());
+ " with " + res.name());