Giter Club home page Giter Club logo

azure-iot-sdk-java's Introduction

Microsoft Azure IoT SDKs for Java

2.0.0 clients release notice

A 2.0.0 release has been published for each package in this library. With this release, all future features will be brought only to this new major version, so users are highly encouraged to migrate from the 1.X.X releases to the new 2.0.0 releases. We have released one final LTS release for the 1.X.X packages that will be supported like any other LTS release.

If you need any help migrating your code to try out the new 2.X.X clients, please see this migration guide.

Critical upcoming change notice

All Azure IoT SDK users are advised to be aware of upcoming TLS certificate changes for Azure IoT hub and Device Provisioning Service that will impact the SDK's ability to connect. In October 2022, both services will migrate from the current Baltimore CyberTrust CA Root to the DigiCert Global G2 CA root. There will be a transition period beforehand where your IoT devices must have both the Baltimore and Digicert public certificates installed in their certificate store in order to prevent connectivity issues.

For a more in depth explanation as to why the IoT services are doing this, please see this article.

Users of this Java IoT SDK in particular will need to follow slightly different instructions in order to handle this upcoming change. See this document for a more in depth explanation of how to prepare your devices for this certificate migration.

Users who don't follow these instructions will begin experiencing unrecoverable, consistent connection failures from their devices starting June 2022.

If you have any questions, comments, or concerns about this upcoming change, please let us know on our discussions page.

Build status

Due to security considerations, build logs are not publicly available.

Service Environment Status
Main Build Status
Preview Build Status

This repository contains the following:

  • Azure IoT Hub device SDK for Java: connect client devices to Azure IoT Hub
  • Azure IoT Device Provisioning device SDK for Java: provision devices to Azure IoT Hub using Azure IoT Device Provisioning
  • Azure IoT Device Provisioning service SDK for Java: manage your Provisioning service instance from a back-end Java application

Note that the IoT Hub service SDK has been moved to this repo.

To find SDKs in other languages for Azure IoT, please refer to the azure-iot-sdks repository

Developing applications for Azure IoT

Visit Azure IoT Dev Center to learn more about developing applications for Azure IoT.

How to use the Azure IoT SDKs for Java

Devices and data sources in an IoT solution can range from a simple network-connected sensor to a powerful, standalone computing device. Devices may have limited processing capability, memory, communication bandwidth, and communication protocol support. The IoT device SDKs enable you to implement client applications for a wide variety of devices.

  • On Linux and Windows:
    • Using Maven: the simplest way to use the Azure IoT SDKs for Java to develop apps is to leverage Maven packages:
    • Clone the repository: git clone https://github.com/Azure/azure-iot-sdk-java.git
    • Working with the SDKs code: if you are working with the SDKs code to modify it or contribute changes, then you can clone the repository and build the libraries:
  • On Android: our Java device SDK can be used on Android:

For more details on what platforms this SDK supports, see this document.

API reference

Key features and roadmap

Device client SDK

✔️ feature available ✖️ feature planned but not supported ➖ no support planned

Features mqtt mqtt-ws amqp amqp-ws https Description
Authentication ✔️ ✔️ ✔️ ✔️ ✔️ Connect your device to IoT Hub securely with supported authentication, including private key, SASToken, X-509 Self Signed over MQTT, AMQPS and HTTPS, and X-509 Certificate Authority (CA) Signed.
Send device-to-cloud message ✔️* ✔️* ✔️* ✔️* ✔️ Send device-to-cloud messages (max 256KB) to IoT Hub with the option to add custom properties. *IoT Hub supports batch send over AMQP and HTTPS at the moment, Java SDK only supports HTTPS. The MQTT and AMQP implementation loops over the batch and sends each message individually.
Receive cloud-to-device messages ✔️* ✔️* ✔️ ✔️ ✔️ Receive cloud-to-device messages and read associated custom and system properties from IoT Hub, with the option to complete/reject/abandon C2D messages. *IoT Hub does not support option to reject/abandon C2D messages over MQTT at the moment.
Device Twins ✔️ ✔️ ✔️ ✔️ IoT Hub persists a device twin for each device that you connect to IoT Hub. The device can perform operations like get twin tags, subscribe to desired properties.
Direct Methods ✔️ ✔️ ✔️ ✔️ IoT Hub gives you the ability to invoke direct methods on devices from the cloud. The SDK supports handler for generic operation.
Upload file to Blob ✔️ A device can initiate a file upload and notifies IoT Hub when the upload is complete. File upload requires HTTPS connection, but can be initiated from client using any protocol for other operations such as telemetry.
Connection Status and Error reporting ✖️ ✖️ ✖️ ✖️ ✖️ Error reporting for IoT Hub supported error code.
Retry policies ✔️ ✔️ ✔️ ✔️ ✔️ Retry policy for unsuccessful device-to-cloud messages have three options: no try, exponential backoff with jitter (default) and custom. Detail implementation is documented here.
Devices multiplexing over single connection ✔️ ✔️ ✖️
Connection Pooling * Specifying number of connections ✖️ ✖️ ✖️

Provisioning client SDK

✔️ feature available ✖️ feature planned but not supported ➖ no support planned This repository contains provisioning device client SDK for the Device Provisioning Service.

Features mqtt mqtt-ws amqp amqp-ws https Description
TPM Individual Enrollment ✔️ ✖️ ✔️ This SDK supports connecting your device to the Device Provisioning Service via individual enrollment using Trusted Platform Module. Please visit the samples folder and this quickstart on how to create a device client. Websocket connection over AMQP is currently not available. TPM over MQTT is currently not supported by the Device Provisioning Service.
X.509 Individual Enrollment ✔️ ✔️ ✔️ ✔️ ✔️ This SDK supports connecting your device to the Device Provisioning Service via individual enrollment using X.509 leaf certificate. Please visit the samples folder and this quickstart on how to create a device client.
X.509 Enrollment Group ✔️ ✔️ ✔️ ✔️ ✔️ This SDK supports connecting your device to the Device Provisioning Service via enrollment group using X.509 root certificate. Please visit the samples folder to learn more about this feature.

Provisioning service client SDK

This repository contains provisioning service client SDK for the Device Provisioning Service to programmatically enroll devices.

Feature Support Description
CRUD Operation with TPM Individual Enrollment ✔️ Programmatically manage device enrollment using TPM with the service SDK. Please visit the samples folder and this quickstart to learn more about this feature.
Bulk CRUD Operation with TPM Individual Enrollment ✔️ Programmatically bulk manage device enrollment using TPM with the service SDK. Please visit the samples folder to learn more about this feature.
CRUD Operation with X.509 Individual Enrollment ✔️ Programmatically manage device enrollment using X.509 individual enrollment with the service SDK. Please visit the samples folder and this quickstart to learn more about this feature.
CRUD Operation with X.509 Group Enrollment ✔️ Programmatically manage device enrollment using X.509 group enrollment with the service SDK. Please visit the samples folder to learn more about this feature.
Query enrollments ✔️ Programmatically query registration states with the service SDK. Please visit the samples folder to learn more about this feature.

Samples

Within the repository, you can find various types of simple samples that can help you get started.

Logging

In order to learn more about logging within this SDK and how to capture its logs, see here.

Contribution, feedback and issues

If you encounter any bugs, have suggestions for new features or if you would like to become an active contributor to this project please follow the instructions provided in the contribution guidelines.

Need support?

  • Have a technical question? Ask on Stack Overflow with tag “azure-iot-hub”
  • Need Support? Every customer with an active Azure subscription has access to support with guaranteed response time. Consider submitting a ticket and get assistance from Microsoft support team
  • Found a bug? Please help us fix it by thoroughly documenting it and filing an issue on GitHub (C, Java, .NET, Node.js, Python).

Here is what you can expect Microsoft Support to be able to help with:

  • Client SDKs issues: If you are trying to compile and run the libraries on a supported platform, the Support team will be able to assist with troubleshooting or questions related to compiler issues and communications to and from the IoT Hub. They will also try to assist with questions related to porting to an unsupported platform, but will be limited in how much assistance can be provided. The team will be limited with trouble-shooting the hardware device itself or drivers and or specific properties on that device.
  • IoT Hub / Connectivity Issues: Communication from the device client to the Azure IoT Hub service and communication from the Azure IoT Hub service to the client. Or any other issues specifically related to the Azure IoT Hub.
  • Portal Issues: Issues related to the portal, that includes access, security, dashboard, devices, Alarms, Usage, Settings and Actions.
  • REST/API Issues: Using the IoT Hub REST/APIs that are documented in the documentation.

Read more

SDK folder structure

/device

Contains Azure IoT Hub client components that provide the raw messaging capabilities of the library. Refer to the API documentation and samples for information on how to use it.

/doc

This folder contains application development guides and device setup instructions.

/iot-e2e-tests

This folder contains end to end tests source code for running on jvm and android.

/vsts

This folder contains scripts to build and run Java SDK provided proper environmental variables are set, as well as azure pipeline resources used for our gating process

Certificates - Important to know

For guidance and important information about certificates, please refer to this blog post from the security team.

Support

The Azure IoT Hub Device Client supported releases is outlined in the following table.

Refer to the Azure IoT Device SDK lifecycle and support for details on the different supported stages.

Release Category End-of-life
2.1.5 Active -
1.34.3 Deprecated 2023-03-30

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Microsoft collects performance and usage information which may be used to provide and improve Microsoft products and services and enhance your experience. To learn more, review the privacy statement.

azure-iot-sdk-java's People

Contributors

abhipsamisra avatar andrew-buckley avatar anhashia avatar anporumb avatar az-iot-builder-01 avatar azabbasi avatar bertkleewein avatar bikamani avatar brycewang-microsoft avatar damonbarry avatar dcristoloveanu avatar dependabot[bot] avatar dominicbetts avatar drwill-ms avatar ewertons avatar iluican avatar jamdavi avatar jasmineymlo avatar jebrando avatar jmayrbaeurl avatar jonathangiles avatar josesimoes avatar mamokarz avatar prmathur-microsoft avatar sharmasejal avatar tameraw avatar timtay-microsoft avatar tmahmood-microsoft avatar vinagesh avatar yzhong94 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

azure-iot-sdk-java's Issues

HTTP Proxy - not working?

I am using the sample in the SDK, for a java service client. I've changed the protocol from AMQP to AMQP.WS,

I've not had any luck in getting this to work over a proxy. I've tried settings the proxy at JVM level with:

-DproxySet=true -Dhttp.proxyHost=proxy.company.com -Dhttp.proxyPort=8080 -Dhttps.proxyHost=proxy.company.com -Dhttps.proxyPort=8080

The SDK insists on trying to connect to azure directly. It doesn't throw any errors, but looking at the trace it should've at least thrown a certficate error because it is retrieving our firewall's ceritificate which is not matching the hostname)

When switching to a network that is not behind the proxy, everything works well.
Am I missing something, or is this a bug / known limitation?

I'm running on Linux, OpenJDK 1.8. We have an unauthenticated proxy.

[Java] No error when sending more than 50 messages (to the same device)

From @dluc on November 29, 2016 2:6

The documentation mentions a limit on the number of messages per device that can be enqueued:

Each device queue holds at most 50 cloud-to-device messages. Trying to send more messages to the same device results in an error

When an application sends more than 50 C2D messages though, no error occurs. The code below for instance, sends 1000 messages to the same device, without throwing any exception.

  1. Are the messages discarded without exceptions after the 50th, or are they actually enqueued (in which case the documentation doesn't reflect the service behavior) ?
  2. If "50" is a soft limit, what is the actual hard limit and what exception should one expect ?

Thanks
Devis

Code:

/* 
    Dependencies:
    iothub-java-service-client  1.0.10
    iothub-java-device-client   1.0.15
*/

import com.microsoft.azure.iot.service.sdk.DeliveryAcknowledgement;
import com.microsoft.azure.iot.service.sdk.IotHubServiceClientProtocol;
import com.microsoft.azure.iot.service.sdk.Message;
import com.microsoft.azure.iot.service.sdk.ServiceClient;

import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.Date;
import java.util.UUID;

public class Test
{
    static String hub = System.getenv("SDK_HUB_NAME");
    static String serviceKey = System.getenv("SDK_SERVICE_KEY");
    static String device = System.getenv("SDK_DEVICE_ID");

    static ServiceClient client;

    public static void main(String[] args) throws Exception
    {
        log("Creating service client");
        String cs = "HostName=" + hub + ".azure-devices.net;SharedAccessKeyName=service;SharedAccessKey=" + serviceKey;
        client = ServiceClient.createFromConnectionString(cs, IotHubServiceClientProtocol.AMQPS);

        log("Open service client connection");
        client.open();

        for (int i = 0; i < 1000; i++) send(i);

        log("Close service client connection");
        client.close();

        log("Done");
    }

    static void send(Integer i) throws Exception
    {
        Message msg = new Message("test".getBytes(StandardCharsets.UTF_8));
        msg.setTo(device);
        msg.setDeliveryAcknowledgement(DeliveryAcknowledgement.Full);
        msg.setExpiryTimeUtc(Date.from(Instant.now().plusSeconds(3600)));
        msg.setMessageId(UUID.randomUUID().toString());

        log("Sending msg #" + i + ", To: '" + device + "', ID: " + msg.getMessageId() + ", Expire: " + msg.getExpiryTimeUtc());
        client.send(device, msg);
    }

    static void log(String text)
    {
        DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss.SSS");
        System.out.println("[" + dateFormat.format(new Date()) + "] " + text);
    }
}

Copied from original issue: Azure/azure-iot-sdks#997

IoT Hub resets the connection

Hi,

we use Java SDK version 1.0.15 on debian and have the problem that we sporadically get into an endless reconnect loop (Lost connection to the server. Reconnection attempt 1368 etc.).
I captured the network traffic using Wireshark. Please take a look at the screenshot:

image

As you can see the connection is first closed by the client (FIN). The SDK seems to do this on its own because we have no code in place that would close the connection (only on app exit).
After this the SDK tries to reconnect and from that point on the connection is reset (RST) by the IoT Hub.
If we kill the process and restart it, it works again for a while until the issue reappears.
We were able to reproduce it on OSX and Windows as well.

Thanks for your support
Best Regards
Vitaliy

UploadToBlobAsync for Java SDK?

Description of the issue: File Upload not supported by current version of Java SDK 1.0.16

Hi, I saw that C# version supports UploadToBlobAsync but Java version not. Any chance we can see this feature soon in Java SDK?

Best,
Milos

[Android] MQTT auto closed after a connection resets

201702010851_MQTT_Azure_SDK_1.0.16_no_stack.txt

Hi Azure team,

I'm running IoT Hub Device SDK 1.0.16 with MQTT protocol on an Android board to send sensors data to back end. The sensor data is collected every 30 seconds.

After running happily for 5 days without interruption, my Android board got a new IP address from the router and Android initiated a connection reset call

D/ConnectivityService( 1976): resetConnections(wlan0, 1)

Immediately after this, the Azure Device threw this exception and refused to work:

02-01 15:27:26.965 I/System.out(14971): java.lang.IllegalStateException: The MQTT connection is currently closed. Call open() before attempting to receive a message.: The MQTT connection is currently closed. Call open() before attempting to receive a message.

02-01 15:27:26.965 I/System.out(14971): com.microsoft.azure.iothub.transport.mqtt.MqttIotHubConnection.receiveMessage(MqttIotHubConnection.java:245)

02-01 15:27:26.965 I/System.out(14971): com.microsoft.azure.iothub.transport.mqtt.MqttTransport.handleMessage(MqttTransport.java:256)

02-01 15:27:26.965 I/System.out(14971): com.microsoft.azure.iothub.transport.IotHubReceiveTask.run(IotHubReceiveTask.java:25)

02-01 15:27:26.965 I/System.out(14971): java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)

02-01 15:27:26.965 I/System.out(14971): java.util.concurrent.FutureTask.runAndReset(FutureTask.java:279)

02-01 15:27:26.965 I/System.out(14971): java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:152)

02-01 15:27:26.975 I/System.out(14971): java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:266)

02-01 15:27:26.975 I/System.out(14971): java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)

02-01 15:27:26.975 I/System.out(14971): java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)

02-01 15:27:26.975 I/System.out(14971): java.lang.Thread.run(Thread.java:841)

This exception is caused when the receiveTask continue to run while the connection has closed. Please see the attached log file for more debug traces.

Could you suggest a way to handle this case?

Best wishes,

Kevin

com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin.start() doesn't set isStarted property correctly

  • OS and version used: Windows 10

  • Java runtime used: 1.8

  • SDK version used: 1.0.21

Description of the issue:

The method MqttDeviceTwin.start() doesn't set the property isStarted to true after a successful start

Code sample exhibiting the issue:

public void start() throws IOException
{
    if (!isStarted)
    {
        /*
        **Codes_SRS_MQTTDEVICETWIN_25_019: [**start method shall subscribe to twin response topic ($iothub/twin/res/#) if connected and throw IoException otherwise.**]**
         */
        this.subscribe(subscribeTopic);
    }
}

Console log of the issue:

com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin.stop() must not be processed when not started yet

  • OS and version used: Windows 10

  • Java runtime used: 1.7

  • SDK version used: 1.0.21

Description of the issue:

When MqttDeviceTwin.stop() gets called without having called MqttDeviceTwin.start() before, the method will try to unsubscribe a topic that wasn't subscribed yet, causing an error. Can be fixed quite easily, by checking the isStarted property (when it's set correctly, see my previous issue)

Code sample exhibiting the issue:

public void stop() throws IOException
{
    /*
    **Codes_SRS_MQTTDEVICETWIN_25_020: [**stop method shall unsubscribe from twin response topic ($iothub/twin/res/#) and throw IoException otherwise.**]**
     */
    this.unsubscribe(subscribeTopic);
}

Console log of the issue:

azure-iot-sdk-java/tree/master/device package names to not match folder hierarchy

Take a look at line 4 of https://github.com/Azure/azure-iot-sdk-java/blob/master/device/iot-device-samples/device-twin-sample/src/main/java/samples/com/microsoft/azure/sdk/iot/DeviceTwinSample.java. This name does not match with the folder structure as a result the project is broken in my ide. Please fix ASAP. We cannot use like this. Moreover the problem is covered up my the POM file on line 31 https://github.com/Azure/azure-iot-sdk-java/blob/master/device/iot-device-samples/device-twin-sample/pom.xml where the package name is changed during the packaging phase.

Random disconnections on a sample in the azure sdk for java

  • OS and version used:
    Raspbian 8 on a raspberry pi 3
  • Java runtime used:
    jdk-8-oracle-arm32
  • SDK version used:
    im using the send-receive-samples version 1.0.14 include in the sdk for java

Description of the issue:

When i connect to the iot hub, im using the HostName=;DeviceId=;SharedAccessKey=;
It connects fine and i can receive messages, which is why im using this sample, but after a while, between 45 minutes and two hours,it disconnects. Im using the AMQPS protocol, but this behavior is the same for MQTT and amqps_ws.
This happend all the time i run the sample, and the reconnection method doesnt do anything, just stay on attempt number 1.
lost
For the enviroment im using, i need the application running all the time and if for some reason fail, that it can be able to reconnect. Is there a possible way of doing this?

Code sample exhibiting the issue:

This is the reconnect method that the sample is using.
reconn
And this is the connectionLost which it refers.
connlost

Wrong CALLING_METHOD_NAME_DEPTH of com.microsoft.azure.sdk.iot.device.CustomLogger

  • OS and version used: Android 4.4.2 KitKat API 19

  • Java runtime used: 1.8

  • SDK version used: 1.0.20

//CustomLogger usage
logger.LogInfo("SAS Token is created successfully, method name is %s ", logger.getMethodName());

//com.microsoft.azure.sdk.iot.device.CustomLogger.java
//Implementation of CustomLogger.getMethodName
 private static final int CALLING_METHOD_NAME_DEPTH = 2;

public String getMethodName()
    {
        return Thread.currentThread().getStackTrace()[CALLING_METHOD_NAME_DEPTH].getMethodName();
    }

While correct name is in depth 3. See picture

c2d41e19676d16b5f7d8736804f046a4

631370fa62840c105b241bd77c9a2918

[java] send-receive-sample does not work with amqps

From @gemehendrix on December 22, 2016 16:5

I've been trying to incorporate the azure iot device client java library into a piece of software I'm writing. It appears HTTPS is working ok but AMQPS and MQTT are not. I have tried the tokens I'm using with a simple C# program and it works fine.

I then tried using the sample applications provided to see if this was something I was doing. It appears the sample applications exhibit the same problem.

I tried running the 'sample-receive-sample' with AMQPS and get the follow errors in my output...

Starting...
Beginning setup.
Successfully read input parameters.
Using communication protocol AMQPS.
Successfully created an IoT Hub client.
Successfully set message callback.
Opened connection to IoT Hub.
Beginning to receive messages...
Sending the following event messages:
Updated token expiry time to 2400
Event Message 0
Press any key to exit...
Lost connection to the server. Reconnection attempt 1...
Lost connection to the server. Reconnection attempt 2...
IoT Hub responded to message 0 with status MESSAGE_EXPIRED
Lost connection to the server. Reconnection attempt 3...
Lost connection to the server. Reconnection attempt 4...
Lost connection to the server. Reconnection attempt 5...
Lost connection to the server. Reconnection attempt 6...
Lost connection to the server. Reconnection attempt 7...
Lost connection to the server. Reconnection attempt 8...
Lost connection to the server. Reconnection attempt 9...
Lost connection to the server. Reconnection attempt 10...

Note the reconnection attempts. This is the same message I get in my own application. MQTT is different. I just don't get any responses. As I mentioned before, it's ok with HTTPS.

I have ruled out token and firewall issues by creating a separate C# program with the same parameters.

Please note, I am using a connection string in the following format...

HostName=<hostName>;DeviceId=<deviceId>;SharedAccessSignature=<SharedAccessSignature>

Update: this works if I use a SASToken created from the device key. This problem only occurs when I use a SAS token created from the server key.

Copied from original issue: Azure/azure-iot-sdks#1032

[Java] ABANDONed messages have status == "unknown" after reaching max number of attempts

From @dluc on December 6, 2016 5:58

When a C2D message is abandoned several times by a device, the final status of the message ("feedback record") is "unknown". Should the status say something about the failed delivery, like the description text?

Code: https://gist.github.com/dluc/ef348f8c3f11f294f31db12c23289f27

Example output, see "status code = unknown"

[21:53:23.727] Creating sender client
[21:53:23.727] Creating message receiver client
[21:53:23.747] Opening message receiver connection
[21:53:23.902] Open sender connection
[21:53:23.904] Sending message, Content: test, ID: 2f017fb4-6b30-4920-9518-d96733e9301f
[21:53:26.220] Message received: Content: test, ID: 2f017fb4-6b30-4920-9518-d96733e9301f
[21:53:26.220] Replying with ABANDON
[21:53:26.473] Message received: Content: test, ID: 2f017fb4-6b30-4920-9518-d96733e9301f
[21:53:26.473] Replying with ABANDON
[21:53:26.725] Message received: Content: test, ID: 2f017fb4-6b30-4920-9518-d96733e9301f
[21:53:26.725] Replying with ABANDON
[21:53:26.984] Message received: Content: test, ID: 2f017fb4-6b30-4920-9518-d96733e9301f
[21:53:26.984] Replying with ABANDON
[21:53:27.264] Message received: Content: test, ID: 2f017fb4-6b30-4920-9518-d96733e9301f
[21:53:27.264] Replying with ABANDON
[21:53:27.584] Message received: Content: test, ID: 2f017fb4-6b30-4920-9518-d96733e9301f
[21:53:27.584] Replying with ABANDON
[21:53:27.852] Message received: Content: test, ID: 2f017fb4-6b30-4920-9518-d96733e9301f
[21:53:27.852] Replying with ABANDON
[21:53:28.123] Message received: Content: test, ID: 2f017fb4-6b30-4920-9518-d96733e9301f
[21:53:28.123] Replying with ABANDON
[21:53:28.372] Message received: Content: test, ID: 2f017fb4-6b30-4920-9518-d96733e9301f
[21:53:28.372] Replying with ABANDON
[21:53:28.622] Message received: Content: test, ID: 2f017fb4-6b30-4920-9518-d96733e9301f
[21:53:28.622] Replying with ABANDON
[21:53:31.218] Creating feedback receiver client
[21:53:31.224] Open feedback receiver connection
[21:53:31.225] Checking the status of the message...
[21:53:31.225] Retrieving feedback batch...
[21:53:32.682] Found feedback batch, size 1
[21:53:32.682] Batch record 731087f3-91bb-42b5-9dd6-6afcb2807db9
[21:53:32.683] Retrieving feedback batch...
[21:53:34.258] Found feedback batch, size 1
[21:53:34.258] Batch record 2f017fb4-6b30-4920-9518-d96733e9301f
[21:53:34.258] Message 2f017fb4-6b30-4920-9518-d96733e9301f feedback found: description = Max delivery count exceeded; status code = unknown
[21:53:34.258] Close feedback receiver connection
[21:53:34.259] Closing message receiver
[21:53:34.270] Done

Copied from original issue: Azure/azure-iot-sdks#1016

Eclipse usage - Use standard package names to avoid package declaration errors

  • OS and version used: Windows 10

  • Java runtime used: 1.8

  • SDK version used: 1.0.21

Description of the issue:

When using Eclipse or the Spring Tool Suite the test classes can't be compiled without errors, because some are using the wrong package declarations in their source code file. Eclipse will show the following error 'The declared package "com.microsoft.azure.sdk.iot.device.transport.mqtt" does not match the expected package
"tests.unit.com.microsoft.azure.sdk.iot.device.transport.mqtt"'.

Code sample exhibiting the issue:

E.g. the test class tests/unit/com/microsoft/azure/sdk/iot/device/transport/mqtt/MqttDeviceTwinTest.java has the following package declaration in its source file:

package com.microsoft.azure.sdk.iot.device.transport.mqtt;

And Eclipse is expecting:

package tests.unit.com.microsoft.azure.sdk.iot.device.transport.mqtt;

Neither Maven, the Java Compiler nor IntelliJ IDE have a problem with this wrong usage of package declaration. Unfortunately Eclipse does and it can't be configured to ignore these errors.

The best way to solve this problem is to remove the additional prefix 'tests.unit' and put the test classes in the same folder hierarchy as the main classes.

Console log of the issue:

[Android-MQTT] Azure device disconnects after 22 hours and fails to reconnect

  • OS and version used: Android 4.4.2

  • Java runtime used: N/A

  • SDK version used: 1.0.20

Description of the issue:

The Android application is set up to transmit sensory data to Cloud service using MQTT. After running for 22 hours. The Device seems to lose connection to the Cloud service and forever tries to reconnect without success.

Code sample exhibiting the issue:

@Override
    public void connectionLost(Throwable throwable)
    {
        synchronized (Mqtt.MQTT_LOCK)
        {

            if (Mqtt.info != null && Mqtt.info.mqttAsyncClient != null)
            {
                int currentReconnectionAttempt = 0;
                while (!Mqtt.info.mqttAsyncClient.isConnected())
                {
                    System.out.println("Lost connection to the server. Reconnecting " + currentReconnectionAttempt + " time.");
                    try
                    {
                        currentReconnectionAttempt++;
                        connect();

                    }
                    catch (Exception e)
                    {
                        try
                        {
                            /*
                            Codes_SRS_Mqtt_25_027: [**The function shall attempt to reconnect to the IoTHub in a loop with exponential backoff until it succeeds**]**
                             */
                            /*
                            **Codes_SRS_Mqtt_25_028: [**The maximum wait interval until a reconnect is attempted shall be 60 seconds.**]**
                             */
                            Thread.sleep(TransportUtils.generateSleepInterval(currentReconnectionAttempt));
                        }
                        catch (InterruptedException ie)
                        {
                            // do nothing and continue trying...
                        }
                    }
                }
            }
            else
            {
                System.out.println("Initialise before using this..");
            }
        }
    }

Console log of the issue:

03-15 15:25:39.628 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 0 time.
03-15 15:25:41.088 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 1 time.
03-15 15:25:41.868 10648-10680/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:25:41.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:25:43.308 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 2 time.
03-15 15:25:47.688 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 3 time.
03-15 15:25:55.968 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 4 time.
03-15 15:26:01.868 10648-10682/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:26:01.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:26:12.298 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 5 time.
03-15 15:26:21.868 10648-10684/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:26:21.878 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:26:26.678 10648-10648/com.myApp D/Hub: Wifi Scan complete
03-15 15:26:26.678 10648-10648/com.myApp D/Hub: WAP node: 9c:97:26:72:d6:a5
03-15 15:26:26.678 10648-10648/com.myApp D/Hub: WAP node: 00:1d:aa:35:ea:80
03-15 15:26:26.678 10648-10648/com.myApp D/Hub: WAP node: 00:50:7f:aa:36:80
03-15 15:26:41.868 10648-10682/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:26:41.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:26:47.618 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 6 time.
03-15 15:27:01.868 10648-10680/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:27:01.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:27:21.868 10648-10683/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:27:21.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:27:41.868 10648-10684/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:27:41.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:27:52.218 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 7 time.
03-15 15:28:01.868 10648-10682/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:28:01.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:28:21.868 10648-10680/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:28:21.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:28:41.868 10648-10683/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:28:41.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:28:52.538 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 8 time.
03-15 15:29:01.868 10648-10684/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:29:01.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:29:21.858 10648-10648/com.myApp D/Hub: Connection status update
03-15 15:29:21.858 10648-10648/com.myApp D/Hub: Connection status metric: 0.0
03-15 15:29:21.878 10648-10680/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:29:21.878 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:29:25.108 10648-10648/com.myApp D/Hub: Wifi Scan complete
03-15 15:29:25.108 10648-10648/com.myApp D/Hub: WAP node: 9c:97:26:72:d6:a5
03-15 15:29:25.108 10648-10648/com.myApp D/Hub: WAP node: 00:1d:aa:35:ea:80
03-15 15:29:25.108 10648-10648/com.myApp D/Hub: WAP node: 9c:97:26:76:89:93
03-15 15:29:41.868 10648-10684/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:29:41.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:29:52.968 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 9 time.
03-15 15:30:01.868 10648-10682/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:30:01.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:30:21.868 10648-10683/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:30:21.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:30:41.868 10648-10680/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:30:41.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:30:53.338 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 10 time.
03-15 15:31:01.868 10648-10684/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:31:01.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:31:21.868 10648-10682/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:31:21.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:31:41.868 10648-10683/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:31:41.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:31:53.628 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 11 time.
03-15 15:32:01.868 10648-10680/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:32:01.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:32:21.878 10648-10684/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:32:21.888 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:32:25.128 10648-10648/com.myApp D/Hub: Wifi Scan complete
03-15 15:32:25.128 10648-10648/com.myApp D/Hub: WAP node: 9c:97:26:72:d6:a5
03-15 15:32:25.138 10648-10648/com.myApp D/Hub: WAP node: 00:1d:aa:35:ea:80
03-15 15:32:25.138 10648-10648/com.myApp D/Hub: WAP node: 9c:97:26:76:89:93
03-15 15:32:41.868 10648-10680/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:32:41.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:32:54.548 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 12 time.
03-15 15:33:01.868 10648-10682/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:33:01.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:33:21.148 10648-10668/com.myApp I/JuniperAmqp: AMQP messages sent: 2146, bytes: 185742
03-15 15:33:21.868 10648-10683/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:33:21.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:33:41.868 10648-10684/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:33:41.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:33:54.808 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 13 time.
03-15 15:34:01.868 10648-10680/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:34:01.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:34:21.858 10648-10648/com.myApp D/Hub: Connection status update
03-15 15:34:21.858 10648-10648/com.myApp D/Hub: Connection status metric: 0.0
03-15 15:34:21.868 10648-10682/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:34:21.878 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:34:41.868 10648-10680/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:34:41.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:34:55.238 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 14 time.
03-15 15:35:01.868 10648-10684/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:35:01.878 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:35:21.868 10648-10683/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:35:21.878 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:35:25.108 10648-10648/com.myApp D/Hub: Wifi Scan complete
03-15 15:35:25.108 10648-10648/com.myApp D/Hub: WAP node: 9c:97:26:72:d6:a5
03-15 15:35:25.108 10648-10648/com.myApp D/Hub: WAP node: 00:1d:aa:35:ea:80
03-15 15:35:25.118 10648-10648/com.myApp D/Hub: WAP node: 9c:97:26:76:89:93
03-15 15:35:41.868 10648-10680/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:35:41.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:35:55.518 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 15 time.
03-15 15:36:01.868 10648-10684/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:36:01.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:36:21.868 10648-10684/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:36:21.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:36:41.868 10648-10683/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:36:41.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:36:55.808 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 16 time.
03-15 15:37:01.868 10648-10680/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:37:01.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:37:21.868 10648-10680/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:37:21.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:37:41.868 10648-10684/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:37:41.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:37:56.138 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 17 time.
03-15 15:38:01.868 10648-10683/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:38:01.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:38:21.868 10648-10683/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:38:21.888 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:38:25.068 10648-10648/com.myApp D/Hub: Wifi Scan complete
03-15 15:38:25.068 10648-10648/com.myApp D/Hub: WAP node: 9c:97:26:72:d6:a5
03-15 15:38:25.068 10648-10648/com.myApp D/Hub: WAP node: 00:1d:aa:35:ea:80
03-15 15:38:25.068 10648-10648/com.myApp D/Hub: WAP node: 00:1d:aa:35:ea:81
03-15 15:38:41.868 10648-10682/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:38:41.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:38:57.418 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 18 time.
03-15 15:39:01.868 10648-10680/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:39:01.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:39:21.858 10648-10648/com.myApp D/Hub: Connection status update
03-15 15:39:21.858 10648-10648/com.myApp D/Hub: Connection status metric: 0.0
03-15 15:39:21.868 10648-10684/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:39:21.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:39:41.868 10648-10680/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:39:41.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:39:57.658 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 19 time.
03-15 15:40:01.868 10648-10682/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:40:01.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:40:21.868 10648-10682/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:40:21.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:40:41.868 10648-10684/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:40:41.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:40:58.088 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 20 time.
03-15 15:41:01.868 10648-10680/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:41:01.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:41:21.878 10648-10683/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:41:21.888 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:41:25.008 10648-10648/com.myApp D/Hub: Wifi Scan complete
03-15 15:41:25.008 10648-10648/com.myApp D/Hub: WAP node: 9c:97:26:72:d6:a5
03-15 15:41:25.008 10648-10648/com.myApp D/Hub: WAP node: 00:1d:aa:35:ea:80
03-15 15:41:25.008 10648-10648/com.myApp D/Hub: WAP node: 00:1d:aa:35:ea:81
03-15 15:41:41.868 10648-10680/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:41:41.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:41:58.348 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 21 time.
03-15 15:42:01.868 10648-10682/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:42:01.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:42:21.868 10648-10684/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:42:21.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:42:41.868 10648-10683/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:42:41.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:42:58.558 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 22 time.
03-15 15:43:01.868 10648-10680/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:43:01.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:43:21.148 10648-10668/com.myApp I/JuniperAmqp: AMQP messages sent: 2146, bytes: 185742
03-15 15:43:21.868 10648-10680/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:43:21.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:43:41.868 10648-10684/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:43:41.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:43:58.888 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 23 time.
03-15 15:44:01.868 10648-10683/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:44:01.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:44:21.858 10648-10648/com.myApp D/Hub: Connection status update
03-15 15:44:21.858 10648-10648/com.myApp D/Hub: Connection status metric: 0.0
03-15 15:44:21.878 10648-10682/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:44:21.888 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:44:25.028 10648-10648/com.myApp D/Hub: Wifi Scan complete
03-15 15:44:25.028 10648-10648/com.myApp D/Hub: WAP node: 9c:97:26:72:d6:a5
03-15 15:44:25.028 10648-10648/com.myApp D/Hub: WAP node: 00:1d:aa:35:ea:80
03-15 15:44:25.028 10648-10648/com.myApp D/Hub: WAP node: 00:1d:aa:35:ea:81
03-15 15:44:41.868 10648-10683/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:44:41.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:44:59.138 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 24 time.
03-15 15:45:01.868 10648-10680/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:45:01.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:45:21.868 10648-10680/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:45:21.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:45:22.478 10648-10655/com.myApp D/dalvikvm: Debugger has detached; object registry had 1 entries
03-15 15:45:41.868 10648-10682/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:45:41.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:45:59.398 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 25 time.
03-15 15:46:01.868 10648-10682/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:46:01.878 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:46:21.868 10648-10684/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:46:21.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:46:41.868 10648-10680/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:46:41.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:46:59.588 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 26 time.
03-15 15:47:01.868 10648-10683/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:47:01.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:47:21.878 10648-10682/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:47:21.888 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:47:25.028 10648-10648/com.myApp D/Hub: Wifi Scan complete
03-15 15:47:25.028 10648-10648/com.myApp D/Hub: WAP node: 9c:97:26:72:d6:a5
03-15 15:47:25.038 10648-10648/com.myApp D/Hub: WAP node: 00:1d:aa:35:ea:80
03-15 15:47:25.038 10648-10648/com.myApp D/Hub: WAP node: 00:1d:aa:35:ea:81
03-15 15:47:41.868 10648-10683/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:47:41.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:47:59.838 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 27 time.
03-15 15:48:01.868 10648-10684/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:48:01.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:48:21.868 10648-10680/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:48:21.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:48:41.868 10648-10682/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:48:41.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:49:00.038 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 28 time.
03-15 15:49:01.868 10648-10682/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:49:01.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:49:21.858 10648-10648/com.myApp D/Hub: Connection status update
03-15 15:49:21.858 10648-10648/com.myApp D/Hub: Connection status metric: 0.0
03-15 15:49:21.868 10648-10680/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:49:21.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:49:41.868 10648-10682/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:49:41.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:50:00.258 10648-10990/com.myApp I/System.out: Lost connection to the server. Reconnecting 29 time.
03-15 15:50:01.868 10648-10683/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:50:01.868 10648-10648/com.myApp D/Hub: Traffic Update
03-15 15:50:21.868 10648-10684/com.myApp D/ConnectionManager: Data usage: 1, 1, of which mobile: 0, 0
03-15 15:50:21.878 10648-10648/com.myApp D/Hub: Traffic Update

Documentation links broken

I’m trying to follow the Java SDK sample. I’m on this page https://github.com/azure/azure-iot-sdk-java , then I click on Simple send sample and I don’t get any instructions. Just another folder to finally find the code.

https://github.com/Azure/azure-iot-sdk-java/tree/master/device/samples/send-event

Is this supposed to work this way?

Also, the Run Java Sample link seems like it suffered some trouble on the migration, cause I get a 404. https://github.com/Azure/azure-iot-sdk-java/blob/doc/get_started/java-run-sample.md

Android Java SDK - IotHubEventCallback not called after sendEventAsync

From @kevin-ledinh on November 23, 2016 10:56

Hi Azure team,

Please advise the following problem when I run the IoT Hub Java SDK to send msg iva AMQP on an Android dev board.

In my first set up, I've been using IoT Hub SDK 1.0.11 and proton-j-azure-iot-0.12.2 (downloaded from Maven repo: https://mvnrepository.com/artifact/com.microsoft.azure.iot/proton-j-azure-iot/0.12.2). With this set up, I am able to send messages to the Could (via sendEventAsync) and receive acknowledgement (via IotHubEventCallback).

In the second set up, a compiled version of the IoT Hub SDK 1.0.15 is used. It is pulled from Maven Repo. I've also checked that the connection string is valid. However, the behaviour is quite different as follows:

  • It takes three minutes for the DeviceClient.open() to return. Looking in AmqpIotHubConnection.java, openLock.waitLock(maxWaitTimeForOpeningClosingConnection) is where the wait is. Is this necessary?

  • Acknowledgement are not received on the device any more. The implementation of IotHubEventCallback is not called. I used both break points and printing out messages to ADB to confirm this and neither happen. Could you advise on how to investigate and fix this?

Any help appreciated. Best wishes,

Kevin

Copied from original issue: Azure/azure-iot-sdks#986

[Java Device Client]Configurable ping interval

From @BlueBasher on June 23, 2016 15:50

The Java Device Client sends a ping message every 120 seconds.
This is different than the .NET Client, which sends a ping every 230 seconds.

The behavior of both clients should at least be the same.
Even more preferable would be to be able to configure this interval.

Copied from original issue: Azure/azure-iot-sdks#653

[Java] REJECTed messages have status == "unknown"

From @dluc on December 6, 2016 5:46

When a C2D message is rejected by a device, the status of the message ("feedback record") is "unknown".

Code: https://gist.github.com/dluc/b5dd54b307b312b74ecb6b25ab4a865d

Example output, see "status code = unknown"

[21:39:34.880] Creating sender client
[21:39:34.880] Creating message receiver client
[21:39:34.912] Opening message receiver connection
[21:39:35.088] Open sender connection
[21:39:35.089] Sending message, Content: test, ID: 731087f3-91bb-42b5-9dd6-6afcb2807db9
[21:39:36.443] Message received: Content: test, ID: 731087f3-91bb-42b5-9dd6-6afcb2807db9
[21:39:36.443] Replying with REJECT
[21:39:41.237] Creating feedback receiver client
[21:39:41.241] Open feedback receiver connection
[21:39:41.242] Checking the status of the message...
[21:39:41.242] Retrieving feedback batch...
[21:39:48.878] Found feedback batch, size 1
[21:39:48.878] Batch record 731087f3-91bb-42b5-9dd6-6afcb2807db9
[21:39:48.879] Message 731087f3-91bb-42b5-9dd6-6afcb2807db9 feedback found: description = Message rejected; status code = unknown
[21:39:48.879] Close feedback receiver connection
[21:39:48.879] Closing message receiver
[21:39:48.890] Done

Copied from original issue: Azure/azure-iot-sdks#1015

Java Service SDK - Cloud 2 Device client hanging and doesn't throw any error when the connection string is incorrect

From @dluc on November 9, 2016 20:48

code: https://gist.github.com/dluc/adb431f0cfd67e55e4bf6dbd30e039ae

Note: the code is a copy of the sample code from the SDK, with a fake connection string and a fake deviceID for the purpose of the test.

The code as is doesn't throw any error and the client seems to hang forever.
It's not possible to understand if a message is delivered.

Output:

Preparing message...
HostName=iothubreact-demo5p-temper.azure-devices.net;SharedAccessKeyName=service;SharedAccessKey=7YMwcekzZdESRB9OcNJiUH61f+N3mj1K//T1jFyejP8=
Creating client to iothubreact-demo5p-temper.azure-devices.net...
Connecting to iothubreact-demo5p-temper.azure-devices.net...
Sending message...
Nov 09, 2016 12:39:27 PM org.apache.qpid.proton.engine.impl.ssl.SslEngineFacadeFactory getClass
WARNING: unable to load org.bouncycastle.openssl.PEMReader
Nov 09, 2016 12:39:27 PM org.apache.qpid.proton.engine.impl.ssl.SslEngineFacadeFactory getClass
WARNING: unable to load org.bouncycastle.openssl.PasswordFinder
Nov 09, 2016 12:39:27 PM org.apache.qpid.proton.engine.impl.ssl.SslEngineFacadeFactory <clinit>
WARNING: unable to load bouncycastle provider

Using com.microsoft.azure.iothub-java-client:iothub-java-service-client:1.0.10

Copied from original issue: Azure/azure-iot-sdks#938

Twin support

Most of the other language SDKs have twin support. Is this coming soon to the java base?

[Android] Azure iot sdk, Can't run sample for android

Hi, I've tried to run sample https://github.com/Azure/azure-iot-sdk-java/tree/master/device/iot-device-samples/android-sample. Build completes successfully, but when I'm trying to run it, packaging always fails with the following error:
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK thirdpartynotice.txt
File1: ...\Users....gradle\caches\modules-2\files-2.1\com.microsoft.azure.sdk.iot\iot-device-client\1.0.17\5400e262163a15494376dcaeab7db18656768c95\iot-device-client-1.0.17.jar
File2: ...\Users....gradle\caches\modules-2\files-2.1\com.microsoft.azure.sdk.iot.deps\websocket-transport-layer\0.1.2\3f35a8f3a5786a2c22b99b3db29e2550d86f1c2c\websocket-transport-layer-0.1.2.jar

I'm using com.android.tools.build:gradle:2.3.0-beta3 gradle.

Only the way I was able to run sample is replacing "compile ('com.microsoft.azure.sdk.iot:iot-device-client:1.0.17')" line to "compile ('com.microsoft.azure.sdk.iot:iot-device-client:1.0.17') {
exclude group: 'com.microsoft.azure.sdk.iot.deps', module: 'websocket-transport-layer'
}"

P.S. original 1.0.16 version can't be resolved on my side and I had to replace it to 17

Cannot unsubscribe when mqtt client is disconnected

  • OS and version used: Windows 10

  • Java runtime used: java version "1.8.0_121"

  • SDK version used: 'com.microsoft.azure.sdk.iot:iot-device-client:1.0.20'

Description of the issue:

I tried to test Android Sample. I created device id and device key using sample for net. Once I tried to use it for Android I get such error on

public void btnReceiveOnClick(View v) throws URISyntaxException, IOException {
        Button button = (Button) v;

        // Comment/uncomment from lines below to use HTTPS or MQTT protocol
        // IotHubClientProtocol protocol = IotHubClientProtocol.HTTPS;
        IotHubClientProtocol protocol = IotHubClientProtocol.MQTT;

        DeviceClient client = new DeviceClient(connString, protocol);

        if (protocol == IotHubClientProtocol.MQTT)
        {
            MessageCallbackMqtt callback = new MessageCallbackMqtt();
            Counter counter = new Counter(0);
            client.setMessageCallback(callback, counter);
        }
        else
        {
            MessageCallback callback = new MessageCallback();
            Counter counter = new Counter(0);
            client.setMessageCallback(callback, counter);
        }

        try {
            client.open();
.....

client.open();

Exception while opening IoTHub connection: java.io.IOException: Cannot unsubscribe when mqtt client is disconnected

Can you please explain what can cause that error?

Documentation issue

Link to Get Started documents on Readme shows a 404. Right now, there's no way to look for instructions to run the simplesamples, as far as I could find.

Upload files to blob

Hi,

I wrote a device-client application in node.js, which among others uploaded files to blob-storage associated with iot-hub at given interval.

I now have to convert this application to java for another enviroment and I can`t find this functionality in java-sdk.

Why isn`t this functionality yet implemented in java-sdk ?
When will you implement this ?
By browsing the different sdk`s in github I get a feeling that java is not prioritized. I hope my assumptions are not correct..

[Java] RegistryManager.getDevices method returns too few devices

The RegistryManager.getDevices doesn't return the correct number of registered devices when a limit is provided. In my example the IoT Hub contains 3 registered devices. However, when I call the getDevices method with a limit that is less than 12, RegistryManager reports a single device, when limit is increased to up to and including 14, 2 devices are reported. The correct number of devices is only reported when the limit is set to >=15.

String connectionString = String.format("HostName=%s;SharedAccessKeyName=%s;SharedAccessKey=%s",
                HOST_NAME, SA_KEY_NAME, SA_KEY_VALUE);
RegistryManager registryManager = RegistryManager.createFromConnectionString(connectionString);
registryManager.getDevices(10).forEach(d -> System.out.println(d.getDeviceId()));

The snippet above reports only a single device, whereas 3 devices are expected.

This happens using the Java SDK (com.microsoft.azure.iothub-java-client:iothub-java-device-client:1.0.16) with Java 8.

[Java] Device-to-Cloud message property value cannot contain '/' (and other symbols)

From @dluc on December 6, 2016 6:46

While it's fine to set properties with values containing symbols like "/" for C2D messages, the same doesn't work for D2C messages:

The code below throws an exception on d2c.setProperty(key,value):

Exception in thread "main" java.lang.IllegalArgumentException: 
/root/sub is not a valid IoT Hub message property value.

The property value validation in com.microsoft.azure.iothub.MessageProperty ctor is, I think, too strict (and not consistent with the validation used for C2D messages).

public class Test
{
    public static void main(String[] args)
    {
        String key = "location";
        String value = "/root/sub";

        // Service message
        com.microsoft.azure.iot.service.sdk.Message c2d = new com.microsoft.azure.iot.service.sdk.Message();
        java.util.HashMap<String, String> properties = new java.util.HashMap<>();
        properties.put(key, value);
        c2d.setProperties(properties);

        // so far so good ...

        // Device message
        com.microsoft.azure.iothub.Message d2c = new com.microsoft.azure.iothub.Message();
        d2c.setProperty(key, value); // <-- exception here
    }
}

Copied from original issue: Azure/azure-iot-sdks#1017

Cannot change device status using import in update mode via API

We are accessing the IoT messagehub via API using simple scrips in java.

It is not possible to change the state of device(s) to "disabled" using import in update mode. The other parameters are changed properly.
Plus, if I disable a device manually at the portal and then run an update import for this device having the state set to "disabled", the device gets enabled anyway.
So in fact, the device gets into enabled state always after running the update-import for it.

Is this an intention, or a bug?
It might be a problem if one wants to disable more devices in a bulk - in fact, there is no way how to do that.

Thanks for investigation.

Don't use System.out and System.err for logging (in non test classes)

  • OS and version used: Windows 10

  • Java runtime used: 1.7

  • SDK version used: 1.0.21

Description of the issue:

In over hundred of cases System.out.println or System.err.println is used in combination with a logger (Custom logger implementation) to log information in the source code. This is not necessary, since the logger can be configured this way. And the default case, logging to the console, leads to having log information written twice.

Code sample exhibiting the issue:

Console log of the issue:

[Java] DeviceClient creates a "cert.crt" file

From @dluc on November 27, 2016 0:0

I noticed a cert.crt file continuously appearing in the root of a project using com.microsoft.azure.iothub.DeviceClient. Is it possible to fix the SDK, so that the library doesn't write to the filesystem?

import com.microsoft.azure.iothub.DeviceClient;
import com.microsoft.azure.iothub.IotHubClientProtocol;

public class TestDeviceClient
{
    static String hub = System.getenv("SDK_HUB_NAME");
    static String device = System.getenv("SDK_DEVICE_ID");
    static String deviceKey = System.getenv("SDK_DEVICE_KEY");

    public static void main(String[] args) throws Exception
    {
        String cs = "HostName=" + hub + ".azure-devices.net;DeviceId=" + device + ";SharedAccessKey=" + deviceKey;
        DeviceClient client = new DeviceClient(cs, IotHubClientProtocol.AMQPS);
        client.open();
        client.close();
    }
}

cert.crt:

-----BEGIN CERTIFICATE-----
MIIDdzCCAl+gAwIBAgIEAgAAuTANBgkqhkiG9w0BAQUFADBaMQswCQYDVQQGEwJJ
RTESMBAGA1UEChMJQmFsdGltb3JlMRMwEQYDVQQLEwpDeWJlclRydXN0MSIwIAYD
VQQDExlCYWx0aW1vcmUgQ3liZXJUcnVzdCBSb290MB4XDTAwMDUxMjE4NDYwMFoX
DTI1MDUxMjIzNTkwMFowWjELMAkGA1UEBhMCSUUxEjAQBgNVBAoTCUJhbHRpbW9y
...cut...
-----END CERTIFICATE-----

Copied from original issue: Azure/azure-iot-sdks#995

Endless loop in com.microsoft.azure.sdk.iot.device.DeviceClient.close() when remaining messages can't be sent

  • OS and version used: Windows 10

  • Java runtime used: 1.7

  • SDK version used: 1.0.21

Description of the issue:

Calling DeviceClient.close() will end up in an endless loop (see code below -> while (!this.transport.isEmpty()) ) if there are still messages in the queue that haven't been sent to IoT Hub so far. E.g. in case of a missing Internet connection, this will lead to an endless loop.

Code sample exhibiting the issue:

public void close() throws IOException
{
    // Codes_SRS_DEVICECLIENT_11_031: [If the client is already closed, the function shall do nothing.]
    if (this.state == IotHubClientState.CLOSED)
    {
        return;
    }

    // Codes_SRS_DEVICECLIENT_11_010: [The function shall finish all ongoing tasks.]
    // Codes_SRS_DEVICECLIENT_11_011: [The function shall cancel all recurring tasks.]
    while (!this.transport.isEmpty())
    {

    }
    this.taskScheduler.shutdown();
    // Codes_SRS_DEVICECLIENT_11_037: [The function shall close the transport.]
    this.transport.close();
    this.state = IotHubClientState.CLOSED;
}

Console log of the issue:

Don't use log4j directly for logging - Replace with logging facade slf4j

  • OS and version used: Windows 10

  • Java runtime used: 1.8

  • SDK version used: 1.0.21

Description of the issue:

It's best practice to not use a logging implementation like log4j directly, but use a logging facade instead. Then users of the SDK are not forced to use log4j and go with their own choice. Popular logging facade libraries are Apache Commons logging and slf4j. Since only slf4j is still maintained (new versions for actual JRE runtimes available) I would recommend to use slf4j (see https://www.slf4j.org/ )

Code sample exhibiting the issue:

Console log of the issue:

[Java] Unclear behavior for C2D Message Feeback

From @dluc on November 17, 2016 20:57

While debugging the Service SDK sample I noticed that the feedback returned by the SDK is not specific to the messages sent.

How to reproduce:

  • Run the sample code a few times (e.g. 10)
  • Debug the sample code with a breakpoint on line 76 (after FeedbackBatch feedbackBatch = future.get();)
  • Note that feedbackBatch.records includes only 1 record
  • Inspect feedbackBatch.records.get(0).originalMessageId
  • Inspect messageToSend.messageId

The 2 message IDs are not the same, so I assume the feedback doesn't include information about the message sent by the current run, but instead the feedback for a message sent during one of the previous executions.

  1. Could you clarify this behavior, is it documented?
  2. Should a client request the feedback multiple times until it gets the right one?
  3. Why doesn't the batch include the feedback for all the messages sent?

Copied from original issue: Azure/azure-iot-sdks#968

Message Id not sent when using HTTPS or MQTT

We have the following code for sending a message

	Message msg = new Message(msgStr);
	String msgID = java.util.UUID.randomUUID().toString();
	msg.setMessageId(msgID);
					
	Object lockobj = new Object();
	EventCallback callback = new EventCallback();
	client.sendEventAsync(msg, callback, lockobj);

When we set the protocol to IotHubClientProtocol.AMQPS we can see the message id making it up to IoTHub as expected. When we use either IotHubClientProtocol.HTTPS or IotHubClientProtocol.MQTT the resulting message do not contain a message id

[Java] Incorrect packages in JCenter/Bintray leading to inconsistent behavior

From @dluc on November 30, 2016 0:20

Some IDEs, e.g. Scala developers using SBT, are commonly setup to look for packages also in JCenter/Bintray, other than Maven Central. In this case some developers will experience odd SDK behavior, because the versions published are not consistent.

For instance, it took several hours to debug an issue that was affecting only Scala (missing classes loaded by SSlEngineFacadeFactory), to finally discover that Scala was pulling iothub-java-service-client 1.0.10 from Bintray and using Proton-J 0.12.2, while instead Java was pulling from Maven Central and using Proton-J 0.15.0.

Please either remove the wrong packages or make sure they are always in sync. For instance you could publish only snapshots to Bintray, with a "-DEV" suffix (e.g. iothub-java-service-client-1.0.10-DEV).

    <dependency>
      <groupId>org.apache.qpid</groupId>
      <artifactId>proton-j</artifactId>
      <version>0.15.0</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>com.microsoft.azure.iot</groupId>
      <artifactId>proton-j-azure-iot</artifactId>
      <version>0.12.2</version>
      <type>jar</type>
    </dependency>

Copied from original issue: Azure/azure-iot-sdks#1002

[Android]android sample can't receive message

Hi,
I used android sample test send and receive message to and from IoT Hub. send message will feedback: IoT Hub responded to message 0 with status OK_EMPTY, is send message success ? when i clicked receive message button, can't receive message(com.microsoft.azure.sdk.iot.device.MessageCallback nothing feedback).

Help wanted - receiving C2D messages from queue

  • OS and version used: Windows 10

  • Java runtime used: 1.8

  • SDK version used: 1.0.20

Description of the issue:

Hi everyone, can you help me understand this case.
I created the Android app that receive messages from the cloud and .net console app that send messages to the cloud. When Android device is online I get the messages right after I send it it from console app. Which is perfect. Than I close my app on the Android and send several messages. After that Android app back online I get only latest message I sent from console app. I was not able to find any explanation about it in documentation so asked here. I add few pictures to better understand my case.

1

2

Thanks in advance

[Java] Memory leak in AmqpsIotHubConnection

The Delivery object created by sendMessage () is not released.

diff -w -u -r /r/downloads/iothub/transport/amqps/AmqpsIotHubConnection.java /r/downloads/AmqpsIotHubConnection.java 
--- /r/downloads/iothub/transport/amqps/AmqpsIotHubConnection.java	2016-12-02 13:25:22.000000000 +0900
+++ /r/downloads/AmqpsIotHubConnection.java	2016-12-21 10:56:30.000000000 +0900
@@ -339,6 +339,7 @@
             byte[] tag = String.valueOf(this. nextTag++).getBytes();
             Delivery dlv = sender.delivery(tag);
 
+	    try {
             // Codes_SRS_AMQPSIOTHUBCONNECTION_15_018: [The function shall attempt to send the message using the sender link.]
             sender.send(msgData, 0, length);
 
@@ -347,6 +348,11 @@
 
             // Codes_SRS_AMQPSIOTHUBCONNECTION_15_020: [The function shall set the delivery hash to the value returned by the sender link.]
             deliveryHash = dlv.hashCode();
+	    } catch (Exception e) {
+		sender.advance();
+		dlv.free();
+		deliveryHash = -1;
+	    }
         }
 
         // Codes_SRS_AMQPSIOTHUBCONNECTION_15_021: [The function shall return the delivery hash.]
@@ -554,6 +560,7 @@
                 {
                     listener.messageSent(d.hashCode(), state);
                 }
+		d.free();
             }
         }
     }

Java SDK - SendAsync is not thread safe

If I use ServiceClient.SendAsync to send multiple messages at one time and then wait for all of them to complete, I don't get the right set of messages on the device. Instead, I get one message sent multiple times.
Here is what my code was doing -

  • Call serviceClient.sendAsync for a batch of messages (say 20).
  • Collect all the CompletableFutures returned in an array.
  • Wait for all the futures to complete

Expected behavior -

  • I get all the messages (in any order) on the device

Actual behavior -

  • I get one message sent multiple times on the device (for. e.g., instead of "msg1, msg3, msg2, msg4...", I was getting "msg1, msg3, msg2, msg5, msg5, msg5, msg5...." on the device).

If I add a sleep between the sends, then I get the messages properly. So it seems to be because of some internal data structures being shared across threads.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.