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:
- 78:7acff4261af4
- Parent:
- 74:d20e4ff30068
- Child:
- 79:21537a6b9511
--- a/iothub_client_sample_amqp.c Fri Aug 11 14:03:39 2017 -0700 +++ b/iothub_client_sample_amqp.c Fri Aug 25 11:23:59 2017 -0700 @@ -40,6 +40,8 @@ size_t size = 0; const char* messageId; const char* correlationId; + const char* userDefinedContentType; + const char* userDefinedContentEncoding; // Message properties if ((messageId = IoTHubMessage_GetMessageId(message)) == NULL) @@ -52,6 +54,16 @@ correlationId = "<null>"; } + if ((userDefinedContentType = IoTHubMessage_GetContentTypeSystemProperty(message)) == NULL) + { + userDefinedContentType = "<null>"; + } + + if ((userDefinedContentEncoding = IoTHubMessage_GetContentEncodingSystemProperty(message)) == NULL) + { + userDefinedContentEncoding = "<null>"; + } + // Message content IOTHUBMESSAGE_CONTENT_TYPE contentType = IoTHubMessage_GetContentType(message); @@ -59,7 +71,8 @@ { if (IoTHubMessage_GetByteArray(message, &buffer, &size) == IOTHUB_MESSAGE_OK) { - (void)printf("Received Message [%d]\r\n Message ID: %s\r\n Correlation ID: %s\r\n BINARY Data: <<<%.*s>>> & Size=%d\r\n", *counter, messageId, correlationId, (int)size, buffer, (int)size); + (void)printf("Received Message [%d]\r\n Message ID: %s\r\n Correlation ID: %s\r\n Content-Type: %s\r\n Content-Encoding: %s\r\n BINARY Data: <<<%.*s>>> & Size=%d\r\n", + *counter, messageId, correlationId, userDefinedContentType, userDefinedContentEncoding, (int)size, buffer, (int)size); } else { @@ -70,7 +83,8 @@ { if ((buffer = (const unsigned char*)IoTHubMessage_GetString(message)) != NULL && (size = strlen((const char*)buffer)) > 0) { - (void)printf("Received Message [%d]\r\n Message ID: %s\r\n Correlation ID: %s\r\n STRING Data: <<<%.*s>>> & Size=%d\r\n", *counter, messageId, correlationId, (int)size, buffer, (int)size); + (void)printf("Received Message [%d]\r\n Message ID: %s\r\n Correlation ID: %s\r\n Content-Type: %s\r\n Content-Encoding: %s\r\n STRING Data: <<<%.*s>>> & Size=%d\r\n", + *counter, messageId, correlationId, userDefinedContentType, userDefinedContentEncoding, (int)size, buffer, (int)size); // If we receive the work 'quit' then we stop running } @@ -199,6 +213,9 @@ (void)printf("ERROR: Map_AddOrUpdate Failed!\r\n"); } + (void)IoTHubMessage_SetContentTypeSystemProperty(messages[iterator].messageHandle, "application/json"); + (void)IoTHubMessage_SetContentEncodingSystemProperty(messages[iterator].messageHandle, "utf-8"); + if (IoTHubClient_LL_SendEventAsync(iotHubClientHandle, messages[iterator].messageHandle, SendConfirmationCallback, &messages[iterator]) != IOTHUB_CLIENT_OK) { (void)printf("ERROR: IoTHubClient_SendEventAsync..........FAILED!\r\n");