public final class AmqpsTransport extends Object implements IotHubTransport, ServerListener
An AMQPS transport. Contains functionality for adding messages and sending messages to an IoT Hub. Buffers unsent messages until they are received by an IoT Hub. A transport is bound at construction to the following parameters: IoT Hub name, device ID and device key.
The transport also receives messages from IoT Hub and invokes a user-defined message callback if a message and callback are found.| Constructor and Description |
|---|
AmqpsTransport(DeviceClientConfig config,
Boolean useWebSockets)
Constructs an instance from the given
DeviceClientConfig
object. |
| Modifier and Type | Method and Description |
|---|---|
void |
addMessage(Message message,
IotHubEventCallback callback,
Object callbackContext)
Adds a message to the transport queue.
|
void |
close()
Closes all resources used to communicate with an IoT Hub.
|
void |
connectionLost()
If the connection is lost, all the messages in progress are buffered to be sent again.
|
void |
handleMessage()
Invokes the message callback if a message is found and
responds to the IoT Hub on how the processed message should be
handled by the IoT Hub.
|
void |
invokeCallbacks()
Invokes the callbacks for all completed requests.
|
boolean |
isEmpty()
Returns
true if the transport has no more messages to handle,
and false otherwise. |
void |
messageReceived(AmqpsMessage message)
When a message is received, it is added to the list of messages to be processed.
|
void |
messageSent(Integer messageHash,
Boolean deliveryState)
When a message is acknowledged by IoTHub, it is removed from the list of in progress messages and its callback
is added to the list of callbacks to be executed.
|
void |
open()
Establishes a communication channel with an IoT Hub.
|
void |
sendMessages()
Sends all messages from the waiting list, one at a time.
|
public AmqpsTransport(DeviceClientConfig config, Boolean useWebSockets)
DeviceClientConfig
object.config - configuration parameters for an AMQPS session with an IoT HubuseWebSockets - whether the transport should use web sockets or notpublic void open()
throws IOException
open in interface IotHubTransportIOException - if a communication channel cannot be established.public void close()
throws IOException
close() is
called, the transport is no longer usable. If the transport is already
closed, the function shall do nothing.close in interface IotHubTransportclose in interface Closeableclose in interface AutoCloseableIOException - if an error occurs in closing the transport.public void addMessage(Message message, IotHubEventCallback callback, Object callbackContext) throws IllegalStateException
addMessage in interface IotHubTransportmessage - the message to be sent.callback - the callback to be invoked when a response for the message is received.callbackContext - the context to be passed in when the callback is invoked.IllegalStateException - if the transport is closed.public void sendMessages()
throws IOException,
IllegalStateException
Sends all messages from the waiting list, one at a time. If a previous send attempt had failed, the function will attempt to resend the messages in the previous attempt.
sendMessages in interface IotHubTransportIOException - if the server could not be reached.IllegalStateException - if the transport has not been opened or is
already closed.public void invokeCallbacks()
throws IllegalStateException
invokeCallbacks in interface IotHubTransportIllegalStateException - if the transport is closed.public void handleMessage()
throws IllegalStateException
Invokes the message callback if a message is found and responds to the IoT Hub on how the processed message should be handled by the IoT Hub.
If no message callback is set, the function will do nothing.handleMessage in interface IotHubTransportIllegalStateException - if the transport is closed.public void messageSent(Integer messageHash, Boolean deliveryState)
messageSent in interface ServerListenermessageHash - The hash of the message.deliveryState - The state of the delivery.public void connectionLost()
connectionLost in interface ServerListenerpublic void messageReceived(AmqpsMessage message)
messageReceived in interface ServerListenermessage - The message received.public boolean isEmpty()
true if the transport has no more messages to handle,
and false otherwise.isEmpty in interface IotHubTransporttrue if the transport has no more messages to handle,
and false otherwise.Copyright © 2017. All rights reserved.