MqttIotHubConnection Class

public class MqttIotHubConnection implements IotHubTransportConnection

Constructor Summary

Constructor Description
MqttIotHubConnection(ClientConfiguration config)

Constructs an instance from the given ClientConfiguration object.

Method Summary

Modifier and Type Method and Description
void close()

Closes the connection. After the connection is closed, it is no longer usable. If the connection is already closed, the function shall do nothing.

String getConnectionId()

Gives the UUID associated with this connection instance. This string is used in conjunction with the callbacks with connection status updates to ensure that all connection status updates are relevant to this connection object

void onMessageArrived(int messageId)
void open()

Establishes a connection for the device and IoT Hub given in the client configuration. If the connection is already open, the function shall do nothing.

IotHubStatusCode sendMessage(Message message)

Sends an event message.

boolean sendMessageResult(IotHubTransportMessage message, IotHubMessageResult result)

Sends an ACK to the service for the provided message

void setListener(IotHubListener listener)

Sets a listener into the Transport Connection object. This listener updates the Transport layer of connection status updates, message arrivals, and message acknowledgements

Constructor Details

MqttIotHubConnection

public MqttIotHubConnection(ClientConfiguration config)

Constructs an instance from the given ClientConfiguration object.

Parameters:

config - the client configuration.

Throws:

TransportException - if the mqtt connection configuration cannot be constructed.

Method Details

close

public void close()

Closes the connection. After the connection is closed, it is no longer usable. If the connection is already closed, the function shall do nothing.

Overrides:

MqttIotHubConnection.close()

getConnectionId

public String getConnectionId()

Gives the UUID associated with this connection instance. This string is used in conjunction with the callbacks with connection status updates to ensure that all connection status updates are relevant to this connection object

Overrides:

MqttIotHubConnection.getConnectionId()

Returns:

the UUID associated with this connection instance

onMessageArrived

public void onMessageArrived(int messageId)

Parameters:

messageId

open

public void open()

Establishes a connection for the device and IoT Hub given in the client configuration. If the connection is already open, the function shall do nothing.

Overrides:

MqttIotHubConnection.open()

Throws:

TransportException - if a connection could not to be established.

sendMessage

public IotHubStatusCode sendMessage(Message message)

Sends an event message.

Overrides:

MqttIotHubConnection.sendMessage(Message message)

Parameters:

message - the event message.

Returns:

the status code from sending the event message.

Throws:

TransportException - if the MqttIotHubConnection is not open

sendMessageResult

public boolean sendMessageResult(IotHubTransportMessage message, IotHubMessageResult result)

Sends an ACK to the service for the provided message

Overrides:

MqttIotHubConnection.sendMessageResult(IotHubTransportMessage message, IotHubMessageResult result)

Parameters:

message - the message to acknowledge to the service
result - Ignored. The only ack that can be sent in MQTT is COMPLETE

Returns:

true if the ACK was sent successfully and false otherwise

Throws:

TransportException - if the ACK could not be sent successfully

setListener

public void setListener(IotHubListener listener)

Sets a listener into the Transport Connection object. This listener updates the Transport layer of connection status updates, message arrivals, and message acknowledgements

Overrides:

MqttIotHubConnection.setListener(IotHubListener listener)

Parameters:

listener - the listener for connection status updates, message arrivals, and message acknowledgements

Applies to