AMQP Class
Properties Methods Events Configuration Settings Errors
An easy-to-use AMQP 1.0 client implementation.
Syntax
IPWorksIoTAMQP
IPWorksIoTAMQPSwift
Remarks
The AMQP class provides an easy-to-use AMQP 1.0 client implementation. The class supports both plaintext and TLS-enabled connections over TCP.
Connecting
AMQP 1.0's transport protocol has three layers: an overarching connection between two containers, the sessions opened on that connection, and the links (between the containers' nodes) attached to those sessions.The class implements all three layers of the AMQP 1.0 transport protocol, so the first step is to initiate the overall connection. Set the ContainerId property and call the Connect method, passing it the server's hostname and port number.
Once connected, the next step is to create at least one session, which can be accomplished by using the CreateSession method. The class allows creating any number of sessions, up to the limit specified by the MaxSessionCount configuration setting.
Connecting and Creating a Session
amqp1.ContainerId = "testClient";
amqp1.Connect("amqp.test-server.com", 5672);
amqp1.CreateSession("TestSession");
After creating a session, the next step is to create one or more links (which are created in the context of a session) so that messages can be sent and/or received. Links are unidirectional, so each one has a sender on one end and a receiver on the other.
The class can function both as a sender node (by opening sender links) and as a receiver node (by opening receiver links). But keep in mind that, since the class is implemented as an AMQP 1.0 client, it must be the one to open links (said another way, the class cannot accept any link requests made by other peers).
As with sessions, the class allows creating any number of links for each session, up to the limit specified by the MaxLinkCountPerSession configuration setting.
Creating Sender Links
To create a sender link, call the CreateSenderLink method, passing it the name of an existing session, a unique name for the link, and (if necessary in your environment) the name of a target for the receiver to use to ensure messages are routed correctly.The LinkReadyToSend event will fire when the newly created sender link is ready to send messages.
Creating a Sender Link
amqp1.OnLinkReadyToSend += (s, e) => {
Console.WriteLine("Link '" + e.LinkName + "' is ready to send messages!");
};
amqp1.CreateSenderLink("TestSession", "TestSenderLink", "TestTarget");
Sending Messages
To send a message, the first step is to set the Message* properties to the desired values.At minimum, the MessageValue and MessageValueType properties must be set. All other properties are optional, though specifying a unique value for MessageId is recommended. (If the GenerateMessageId configuration setting is enabled, the class will generate one automatically when the message is sent.)
Once the Message* properties have be assigned as desired, call the SendMessage method, passing it the name of an existing sender link on which the message should be sent.
The MessageOut event will be fired when the message has been sent (and acknowledged, if MessageSettled was set to false). The MessageOutcome event may also fire, if necessary, once the receiver reports the outcome of the message.
Refer to SendMessage, MessageOut, and MessageOutcome for more information.
Sending a Message
amqp1.OnMessageOut += (s, e) => {
Console.WriteLine("Message with Id '" + e.MessageId + "' has been sent on link '" + e.LinkName + "'.");
};
amqp1.Message.MessageId = "TestMessageId";
amqp1.Message.Value = "Hello, world!";
amqp1.Message.ValueType = AMQPValueTypes.mvtString;
amqp1.SendMessage("TestSenderLink");
The ResetMessage method can be used to reset the Message* properties to their default values.
Sending Composite AMQP Data
The AMQP 1.0 protocol's data model includes the concept of "composite data". Composite data is comprised of one or more type-value pairs (including data structure types), plus a descriptor that describes what the overall data represents.The class supports sending composite AMQP data in a message through the use of JSON with a well-defined schema. Refer to the SendMessage method's documentation for more information and examples.
Creating Receiver Links
Receiver links can operate in one of two receive modes: automatic, where the class will work to ensure that messages are received as soon as they are available; and fetch-based, where the class will only "fetch" a new message when explicitly instructed to.The ReceiveMode property controls which receive mode newly-created receiver links will use; refer to its documentation for more information.
After ensuring that ReceiveMode is set as desired, call CreateReceiverLink, passing it the name of an existing session, a unique name for the link, and (if necessary in your environment) the name of a source for the sender to route the link creation request to.
Creating a Receiver Link
// Creating an automatic receiver link.
amqp1.ReceiveMode = AmqpReceiveModes.rmAutomatic;
amqp1.CreateReceiverLink("TestSession", "TestAutoReceiverLink", "TestSource1");
// Creating a fetch-based receiver link.
amqp1.ReceiveMode = AmqpReceiveModes.rmFetch;
amqp1.CreateReceiverLink("TestSession", "TestFetchReceiverLink", "TestSource2");
Receiving Messages
For receiver links created in automatic receive mode (the default), messages are received automatically.For receiver links created in fetch-based mode, the class will attempt to "fetch" a message each time the FetchMessage method is called (optionally timing out after a time, if FetchTimeout is non-zero). When calling FetchMessage, pass it the name of a fetch-based receiver link.
Regardless of whether a messages is received automatically or fetched, any incoming message will cause the class to fire the MessageIn event and update the ReceivedMessage* properties.
When the MessageIn event fires, its State event parameter can be used to specify the outcome of the message, which the class will then transmit back to the sender (as well as self-report by firing the MessageOutcome event). Refer to MessageIn for more information.
Receiving a Message
// For automatic receiver links, only the event handler is necessary.
amqp1.OnMessageIn += (s, e) => {
Console.WriteLine("Message with Id '" + e.MessageId + "' has been received on link '" + e.LinkName + "'. Value:");
Console.WriteLine(amqp1.ReceivedMessage.Value);
// The message state is already set to the "Accepted" outcome by default, but we'll set it again
// for the purpose of this example.
e.State = 0; // 0 = Accepted.
};
// For fetch-based links, it's also necessary to call FetchMessage(). It is recommended that the
// FetchTimeout property be set to a non-zero value (60 seconds is the default) so that the fetch
// request will eventually time out if the sender doesn't have any messages available to deliver.
amqp1.FetchTimeout = 60;
amqp1.FetchMessage("TestFetchReceiverLink");
Property List
The following is the full list of the properties of the class with short descriptions. Click on the links for further details.
- authScheme | The authentication scheme to use when connecting. |
- connected | Triggers a connection or disconnection. |
- containerId | The container Id the class should advertise when connecting. |
- fetchTimeout | How long the class should wait for a message to be received after FetchMessage is called. |
- firewallAutoDetect | This property tells the class whether or not to automatically detect and use firewall system settings, if available. |
- firewallType | This property determines the type of firewall to connect through. |
- firewallHost | This property contains the name or IP address of firewall (optional). |
- firewallPassword | This property contains a password if authentication is to be used when connecting through the firewall. |
- firewallPort | This property contains the TCP port for the firewall Host . |
- firewallUser | This property contains a user name if authentication is to be used connecting through a firewall. |
- idleTimeout | The maximum period of inactivity the class will allow before disconnecting. |
- incomingMessageCount | The number of records in the IncomingMessage arrays. |
- incomingMessageAbsoluteExpiryTime:(int)incomingMessageIndex | The absolute time at which this message should be considered expired. |
- incomingMessageContentEncoding:(int)incomingMessageIndex | The content encoding of this message's data. |
- incomingMessageContentType:(int)incomingMessageIndex | The content type of this message's data. |
- incomingMessageCorrelationId:(int)incomingMessageIndex | The correlation Id of this message. |
- incomingMessageCreationTime:(int)incomingMessageIndex | The creation time of this message. |
- incomingMessageDeliveryCount:(int)incomingMessageIndex | How many previous attempts there have been to deliver this message. |
- incomingMessageDurable:(int)incomingMessageIndex | Whether this message is durable. |
- incomingMessageFirstAcquirer:(int)incomingMessageIndex | Whether this message may have been acquired by other links previously. |
- incomingMessageGroupId:(int)incomingMessageIndex | The Id of the group this message belongs to. |
- incomingMessageGroupSequence:(int)incomingMessageIndex | The position of this message within its group. |
- incomingMessageLinkName:(int)incomingMessageIndex | The name of the link this message is associated with. |
- incomingMessageId:(int)incomingMessageIndex | The unique Id of this message. |
- incomingMessagePriority:(int)incomingMessageIndex | The priority of this message. |
- incomingMessageReplyTo:(int)incomingMessageIndex | The address of the node to send replies to for this message. |
- incomingMessageReplyToGroupId:(int)incomingMessageIndex | The Id of the group to send replies to for this message. |
- incomingMessageSettled:(int)incomingMessageIndex | Whether this message is settled. |
- incomingMessageSubject:(int)incomingMessageIndex | The subject of this message. |
- incomingMessageTo:(int)incomingMessageIndex | The address of the node which this message is intended for. |
- incomingMessageTTL:(int)incomingMessageIndex | The time-to-live value for this message. |
- incomingMessageUserId:(int)incomingMessageIndex | The identity of the user responsible for producing this message. |
- incomingMessageValue:(int)incomingMessageIndex | This message's value. |
- incomingMessageValueType:(int)incomingMessageIndex | This message's value data type. |
- linkCount | The number of records in the Link arrays. |
- linkAvailable:(int)linkIndex | The number of messages which this link's sender could send if it had credit for them. |
- linkChannelName:(int)linkIndex | The channel name this link is using. |
- linkCredit:(int)linkIndex | The amount of credit currently available to this link's sender. |
- linkDeliveryCount:(int)linkIndex | The current delivery count value for this link. |
- linkName:(int)linkIndex | This link's name. |
- linkReadyToSend:(int)linkIndex | Whether this link is ready to send a message. |
- linkReceiveMode:(int)linkIndex | The receive mode this link is operating in. |
- linkRole:(int)linkIndex | The class's role on this link. |
- localHost | The name of the local host or user-assigned IP interface through which connections are initiated or accepted. |
- localPort | The TCP port in the local host where the class binds. |
- messageAbsoluteExpiryTime | The absolute time at which this message should be considered expired. |
- messageContentEncoding | The content encoding of this message's data. |
- messageContentType | The content type of this message's data. |
- messageCorrelationId | The correlation Id of this message. |
- messageCreationTime | The creation time of this message. |
- messageDeliveryCount | How many previous attempts there have been to deliver this message. |
- messageDurable | Whether this message is durable. |
- messageFirstAcquirer | Whether this message may have been acquired by other links previously. |
- messageGroupId | The Id of the group this message belongs to. |
- messageGroupSequence | The position of this message within its group. |
- messageLinkName | The name of the link this message is associated with. |
- messageId | The unique Id of this message. |
- messagePriority | The priority of this message. |
- messageReplyTo | The address of the node to send replies to for this message. |
- messageReplyToGroupId | The Id of the group to send replies to for this message. |
- messageSettled | Whether this message is settled. |
- messageSubject | The subject of this message. |
- messageTo | The address of the node which this message is intended for. |
- messageTTL | The time-to-live value for this message. |
- messageUserId | The identity of the user responsible for producing this message. |
- messageValue | This message's value. |
- messageValueType | This message's value data type. |
- outgoingMessageCount | The number of records in the OutgoingMessage arrays. |
- outgoingMessageAbsoluteExpiryTime:(int)outgoingMessageIndex | The absolute time at which this message should be considered expired. |
- outgoingMessageContentEncoding:(int)outgoingMessageIndex | The content encoding of this message's data. |
- outgoingMessageContentType:(int)outgoingMessageIndex | The content type of this message's data. |
- outgoingMessageCorrelationId:(int)outgoingMessageIndex | The correlation Id of this message. |
- outgoingMessageCreationTime:(int)outgoingMessageIndex | The creation time of this message. |
- outgoingMessageDeliveryCount:(int)outgoingMessageIndex | How many previous attempts there have been to deliver this message. |
- outgoingMessageDurable:(int)outgoingMessageIndex | Whether this message is durable. |
- outgoingMessageFirstAcquirer:(int)outgoingMessageIndex | Whether this message may have been acquired by other links previously. |
- outgoingMessageGroupId:(int)outgoingMessageIndex | The Id of the group this message belongs to. |
- outgoingMessageGroupSequence:(int)outgoingMessageIndex | The position of this message within its group. |
- outgoingMessageLinkName:(int)outgoingMessageIndex | The name of the link this message is associated with. |
- outgoingMessageId:(int)outgoingMessageIndex | The unique Id of this message. |
- outgoingMessagePriority:(int)outgoingMessageIndex | The priority of this message. |
- outgoingMessageReplyTo:(int)outgoingMessageIndex | The address of the node to send replies to for this message. |
- outgoingMessageReplyToGroupId:(int)outgoingMessageIndex | The Id of the group to send replies to for this message. |
- outgoingMessageSettled:(int)outgoingMessageIndex | Whether this message is settled. |
- outgoingMessageSubject:(int)outgoingMessageIndex | The subject of this message. |
- outgoingMessageTo:(int)outgoingMessageIndex | The address of the node which this message is intended for. |
- outgoingMessageTTL:(int)outgoingMessageIndex | The time-to-live value for this message. |
- outgoingMessageUserId:(int)outgoingMessageIndex | The identity of the user responsible for producing this message. |
- outgoingMessageValue:(int)outgoingMessageIndex | This message's value. |
- outgoingMessageValueType:(int)outgoingMessageIndex | This message's value data type. |
- password | A password to use for SASL authentication. |
- readyToSend | Indicates whether the class is ready to send data. |
- receivedMessageAbsoluteExpiryTime | The absolute time at which this message should be considered expired. |
- receivedMessageContentEncoding | The content encoding of this message's data. |
- receivedMessageContentType | The content type of this message's data. |
- receivedMessageCorrelationId | The correlation Id of this message. |
- receivedMessageCreationTime | The creation time of this message. |
- receivedMessageDeliveryCount | How many previous attempts there have been to deliver this message. |
- receivedMessageDurable | Whether this message is durable. |
- receivedMessageFirstAcquirer | Whether this message may have been acquired by other links previously. |
- receivedMessageGroupId | The Id of the group this message belongs to. |
- receivedMessageGroupSequence | The position of this message within its group. |
- receivedMessageLinkName | The name of the link this message is associated with. |
- receivedMessageId | The unique Id of this message. |
- receivedMessagePriority | The priority of this message. |
- receivedMessageReplyTo | The address of the node to send replies to for this message. |
- receivedMessageReplyToGroupId | The Id of the group to send replies to for this message. |
- receivedMessageSettled | Whether this message is settled. |
- receivedMessageSubject | The subject of this message. |
- receivedMessageTo | The address of the node which this message is intended for. |
- receivedMessageTTL | The time-to-live value for this message. |
- receivedMessageUserId | The identity of the user responsible for producing this message. |
- receivedMessageValue | This message's value. |
- receivedMessageValueType | This message's value data type. |
- receiveMode | Controls what mode new receiver links are created with. |
- remoteHost | The address of the remote host. Domain names are resolved to IP addresses. |
- remotePort | The port of the AQMP server (default is 5672). The default port for SSL is 5671. |
- sessionCount | The number of records in the Session arrays. |
- sessionIncomingWindow:(int)sessionIndex | The incoming window size of this session. |
- sessionName:(int)sessionIndex | The name of this session. |
- sessionOutgoingWindow:(int)sessionIndex | The outgoing window size of this session. |
- SSLAcceptServerCertEncoded | The certificate (PEM/base64 encoded). |
- SSLCertEncoded | The certificate (PEM/base64 encoded). |
- SSLCertStore | The name of the certificate store for the client certificate. |
- SSLCertStorePassword | If the certificate store is of a type that requires a password, this property is used to specify that password in order to open the certificate store. |
- SSLCertStoreType | The type of certificate store for this certificate. |
- SSLCertSubject | The subject of the certificate used for client authentication. |
- SSLEnabled | Whether TLS/SSL is enabled. |
- SSLServerCertEncoded | The certificate (PEM/base64 encoded). |
- timeout | A timeout for the class. |
- user | A username to use for SASL authentication. |
Method List
The following is the full list of the methods of the class with short descriptions. Click on the links for further details.
- closeLink | Closes a link. |
- closeSession | Closes a session. |
- config | Sets or retrieves a configuration setting. |
- connect | Connects to a remote host. |
- createReceiverLink | Creates a new receiver link with the given name on the specified session. |
- createSenderLink | Creates a new sender link with the given name on the specified session. |
- createSession | Creates a new session with the given name. |
- disconnect | Disconnects from the remote host. |
- doEvents | Processes events from the internal message queue. |
- fetchMessage | Fetches a single message over the specified receiver link. |
- interrupt | Interrupts the current action. |
- reset | Reset the class. |
- resetMessage | Resets the Message properties. |
- sendMessage | Sends a message on the specified link. |
Event List
The following is the full list of the events fired by the class with short descriptions. Click on the links for further details.
- onConnected | Fired immediately after a connection completes (or fails). |
- onConnectionStatus | Fired to indicate changes in connection state. |
- onDisconnected | Fired when a connection is closed. |
- onError | Information about errors during data delivery. |
- onLinkReadyToSend | Fires when a sender link is ready to send messages. |
- onLog | Fires once for each log message. |
- onMessageIn | Fires when the class receives a message. |
- onMessageOut | Fires when the class sends a message. |
- onMessageOutcome | Fires when a message's outcome is available. |
- onSSLServerAuthentication | Fired after the server presents its certificate to the client. |
- onSSLStatus | Shows the progress of the secure connection. |
Configuration Settings
The following is a list of configuration settings for the class with short descriptions. Click on the links for further details.
AuthorizationIdentity | The value to use as the authorization identity when SASL authentication is used. |
DefaultCredit | The amount of credit to create new receiver links with. |
DefaultCreditThreshold | The credit threshold to create new receiver links with. |
DefaultIncomingWindow | The incoming window size to create new sessions with. |
DefaultOutgoingWindow | The outgoing window size to create new sessions with. |
DefaultSenderSettleMode | The sender settle mode to create new links with. |
GenerateMessageId | Whether a unique message Id should be automatically generated when sending a message. |
LogLevel | The level of detail that is logged. |
MaxFrameSize | The maximum frame size. |
MaxLinkCountPerSession | The maximum number of links to restrict new sessions to. |
MaxMessageSize | The maximum message size to restrict new links to. |
MaxSessionCount | The maximum number of sessions. |
ModifiedDeliveryFailed | Whether the sender should treat this transfer as an unsuccessful delivery attempt. |
ModifiedMessageAnnotations | The message annotations that the sender should merge into those already on the message. |
ModifiedUndeliverableHere | Whether the receiver has indicated that the sender should not attempt to redeliver the message. |
ProtocolVersion | The AMQP protocol version to conform to. |
RejectErrorCondition | The error condition included with a 'Rejected' delivery outcome. |
RejectErrorDescription | The error description included with a 'Rejected' delivery outcome. |
SenderSettleMode[LinkName] | Retrieves the negotiated sender settle mode for the specified link. |
SimplifiedJSONFormat | Whether to output simplified JSON where possible. |
ConnectionTimeout | Sets a separate timeout value for establishing a connection. |
FirewallAutoDetect | Tells the class whether or not to automatically detect and use firewall system settings, if available. |
FirewallHost | Name or IP address of firewall (optional). |
FirewallPassword | Password to be used if authentication is to be used when connecting through the firewall. |
FirewallPort | The TCP port for the FirewallHost;. |
FirewallType | Determines the type of firewall to connect through. |
FirewallUser | A user name if authentication is to be used connecting through a firewall. |
KeepAliveInterval | The retry interval, in milliseconds, to be used when a TCP keep-alive packet is sent and no response is received. |
KeepAliveTime | The inactivity time in milliseconds before a TCP keep-alive packet is sent. |
Linger | When set to True, connections are terminated gracefully. |
LingerTime | Time in seconds to have the connection linger. |
LocalHost | The name of the local host through which connections are initiated or accepted. |
LocalPort | The port in the local host where the class binds. |
MaxLineLength | The maximum amount of data to accumulate when no EOL is found. |
MaxTransferRate | The transfer rate limit in bytes per second. |
ProxyExceptionsList | A semicolon separated list of hosts and IPs to bypass when using a proxy. |
TCPKeepAlive | Determines whether or not the keep alive socket option is enabled. |
TcpNoDelay | Whether or not to delay when sending packets. |
UseIPv6 | Whether to use IPv6. |
LogSSLPackets | Controls whether SSL packets are logged when using the internal security API. |
OpenSSLCADir | The path to a directory containing CA certificates. |
OpenSSLCAFile | Name of the file containing the list of CA's trusted by your application. |
OpenSSLCipherList | A string that controls the ciphers to be used by SSL. |
OpenSSLPrngSeedData | The data to seed the pseudo random number generator (PRNG). |
ReuseSSLSession | Determines if the SSL session is reused. |
SSLCACertFilePaths | The paths to CA certificate files on Unix/Linux. |
SSLCACerts | A newline separated list of CA certificate to use during SSL client authentication. |
SSLCheckCRL | Whether to check the Certificate Revocation List for the server certificate. |
SSLCipherStrength | The minimum cipher strength used for bulk encryption. |
SSLEnabledCipherSuites | The cipher suite to be used in an SSL negotiation. |
SSLEnabledProtocols | Used to enable/disable the supported security protocols. |
SSLEnableRenegotiation | Whether the renegotiation_info SSL extension is supported. |
SSLIncludeCertChain | Whether the entire certificate chain is included in the SSLServerAuthentication event. |
SSLNegotiatedCipher | Returns the negotiated ciphersuite. |
SSLNegotiatedCipherStrength | Returns the negotiated ciphersuite strength. |
SSLNegotiatedCipherSuite | Returns the negotiated ciphersuite. |
SSLNegotiatedKeyExchange | Returns the negotiated key exchange algorithm. |
SSLNegotiatedKeyExchangeStrength | Returns the negotiated key exchange algorithm strength. |
SSLNegotiatedVersion | Returns the negotiated protocol version. |
SSLProvider | The name of the security provider to use. |
SSLSecurityFlags | Flags that control certificate verification. |
SSLServerCACerts | A newline separated list of CA certificate to use during SSL server certificate validation. |
TLS12SignatureAlgorithms | Defines the allowed TLS 1.2 signature algorithms when UseInternalSecurityAPI is True. |
TLS12SupportedGroups | The supported groups for ECC. |
TLS13KeyShareGroups | The groups for which to pregenerate key shares. |
TLS13SignatureAlgorithms | The allowed certificate signature algorithms. |
TLS13SupportedGroups | The supported groups for (EC)DHE key exchange. |
AbsoluteTimeout | Determines whether timeouts are inactivity timeouts or absolute timeouts. |
FirewallData | Used to send extra data to the firewall. |
InBufferSize | The size in bytes of the incoming queue of the socket. |
OutBufferSize | The size in bytes of the outgoing queue of the socket. |
BuildInfo | Information about the product's build. |
CodePage | The system code page used for Unicode to Multibyte translations. |
LicenseInfo | Information about the current license. |
ProcessIdleEvents | Whether the class uses its internal event loop to process events when the main thread is idle. |
SelectWaitMillis | The length of time in milliseconds the class will wait when DoEvents is called if there are no events to process. |
UseInternalSecurityAPI | Tells the class whether or not to use the system security libraries or an internal implementation. |