IoTHub raw messaging client sample using AMQP
Dependencies: iothub_client EthernetInterface NTPClient iothub_amqp_transport azure_c_shared_utility mbed-rtos mbed azure_uamqp_c wolfSSL
This sample showcases the usage of Azure IoT client libraries with the AMQP transport for sending/receiving raw messages from an IoT Hub.
Diff: iothub_client_sample_amqp.c
- Revision:
- 40:548ef685e177
- Parent:
- 39:87752a84df87
- Child:
- 43:a4b2614eb860
--- a/iothub_client_sample_amqp.c Sun Apr 24 16:41:50 2016 -0700 +++ b/iothub_client_sample_amqp.c Mon May 09 14:38:01 2016 -0700 @@ -15,7 +15,11 @@ #include "certs.h" #endif // MBED_BUILD_TIMESTAMP +/*String containing Hostname, Device Id & Device Key in the format: */ +/* "HostName=<host_name>;DeviceId=<device_id>;SharedAccessKey=<device_key>" */ +/* "HostName=<host_name>;DeviceId=<device_id>;SharedAccessSignature=<device_sas_token>" */ static const char* connectionString = "[device connection string]"; + static int callbackCounter; DEFINE_ENUM_STRINGS(IOTHUB_CLIENT_CONFIRMATION_RESULT, IOTHUB_CLIENT_CONFIRMATION_RESULT_VALUES); @@ -31,14 +35,28 @@ int* counter = (int*)userContextCallback; const unsigned char* buffer = NULL; size_t size = 0; - + const char* messageId; + const char* correlationId; + + // AMQP message properties + if ((messageId = IoTHubMessage_GetMessageId(message)) == NULL) + { + messageId = "<null>"; + } + + if ((correlationId = IoTHubMessage_GetCorrelationId(message)) == NULL) + { + correlationId = "<null>"; + } + + // AMQP message content. IOTHUBMESSAGE_CONTENT_TYPE contentType = IoTHubMessage_GetContentType(message); if (contentType == IOTHUBMESSAGE_BYTEARRAY) { if (IoTHubMessage_GetByteArray(message, &buffer, &size) == IOTHUB_MESSAGE_OK) { - (void)printf("Received Message [%d] with BINARY Data: <<<%.*s>>> & Size=%d\r\n", *counter, (int)size, buffer, (int)size); + (void)printf("Received Message [%d] (message-id: %s, correlation-id: %s) with BINARY Data: <<<%.*s>>> & Size=%d\r\n", *counter, messageId, correlationId,(int)size, buffer, (int)size); } else { @@ -49,7 +67,7 @@ { if ((buffer = IoTHubMessage_GetString(message)) != NULL && (size = strlen(buffer)) > 0) { - (void)printf("Received Message [%d] with STRING Data: <<<%.*s>>> & Size=%d\r\n", *counter, (int)size, buffer, (int)size); + (void)printf("Received Message [%d] (message-id: %s, correlation-id: %s) with STRING Data: <<<%.*s>>> & Size=%d\r\n", *counter, messageId, correlationId, (int)size, buffer, (int)size); } else {