IPWorks IoT 2020 C++ Builder Edition

Questions / Feedback?

AMQP Component

Properties   Methods   Events   Configuration Settings   Errors  

An easy-to-use AMQP 1.0 client implementation.

Syntax

TiotAMQP

Remarks

The AMQP component provides an easy-to-use AMQP 1.0 client implementation. The component 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 component 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 component 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 component 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 component is implemented as an AMQP 1.0 client, it must be the one to open links (said another way, the component cannot accept any link requests made by other peers).

As with sessions, the component 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 component 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 component 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 component will work to ensure that messages are received as soon as they are available; and fetch-based, where the component 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 component 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 component 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 component 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 component with short descriptions. Click on the links for further details.

AuthSchemeThe authentication scheme to use when connecting.
ConnectedTriggers a connection or disconnection.
ContainerIdThe container Id the component should advertise when connecting.
FetchTimeoutHow long the component should wait for a message to be received after FetchMessage is called.
FirewallAutoDetectThis property tells the component whether or not to automatically detect and use firewall system settings, if available.
FirewallTypeThis property determines the type of firewall to connect through.
FirewallHostThis property contains the name or IP address of firewall (optional).
FirewallPasswordThis property contains a password if authentication is to be used when connecting through the firewall.
FirewallPortThis property contains the TCP port for the firewall Host .
FirewallUserThis property contains a user name if authentication is to be used connecting through a firewall.
IdleTimeoutThe maximum period of inactivity the component will allow before disconnecting.
IncomingMessageCountThe number of records in the IncomingMessage arrays.
IncomingMessageAbsoluteExpiryTimeThe absolute time at which this message should be considered expired.
IncomingMessageContentEncodingThe content encoding of this message's data.
IncomingMessageContentTypeThe content type of this message's data.
IncomingMessageCorrelationIdThe correlation Id of this message.
IncomingMessageCreationTimeThe creation time of this message.
IncomingMessageDeliveryCountHow many previous attempts there have been to deliver this message.
IncomingMessageDurableWhether this message is durable.
IncomingMessageFirstAcquirerWhether this message may have been acquired by other links previously.
IncomingMessageGroupIdThe Id of the group this message belongs to.
IncomingMessageGroupSequenceThe position of this message within its group.
IncomingMessageLinkNameThe name of the link this message is associated with.
IncomingMessageIdThe unique Id of this message.
IncomingMessagePriorityThe priority of this message.
IncomingMessageReplyToThe address of the node to send replies to for this message.
IncomingMessageReplyToGroupIdThe Id of the group to send replies to for this message.
IncomingMessageSettledWhether this message is settled.
IncomingMessageSubjectThe subject of this message.
IncomingMessageToThe address of the node which this message is intended for.
IncomingMessageTTLThe time-to-live value for this message.
IncomingMessageUserIdThe identity of the user responsible for producing this message.
IncomingMessageValueThis message's value.
IncomingMessageValueTypeThis message's value data type.
LinkCountThe number of records in the Link arrays.
LinkAvailableThe number of messages which this link's sender could send if it had credit for them.
LinkChannelNameThe channel name this link is using.
LinkCreditThe amount of credit currently available to this link's sender.
LinkDeliveryCountThe current delivery count value for this link.
LinkNameThis link's name.
LinkReadyToSendWhether this link is ready to send a message.
LinkReceiveModeThe receive mode this link is operating in.
LinkRoleThe component's role on this link.
LocalHostThe name of the local host or user-assigned IP interface through which connections are initiated or accepted.
LocalPortThe TCP port in the local host where the component binds.
MessageAbsoluteExpiryTimeThe absolute time at which this message should be considered expired.
MessageContentEncodingThe content encoding of this message's data.
MessageContentTypeThe content type of this message's data.
MessageCorrelationIdThe correlation Id of this message.
MessageCreationTimeThe creation time of this message.
MessageDeliveryCountHow many previous attempts there have been to deliver this message.
MessageDurableWhether this message is durable.
MessageFirstAcquirerWhether this message may have been acquired by other links previously.
MessageGroupIdThe Id of the group this message belongs to.
MessageGroupSequenceThe position of this message within its group.
MessageLinkNameThe name of the link this message is associated with.
MessageIdThe unique Id of this message.
MessagePriorityThe priority of this message.
MessageReplyToThe address of the node to send replies to for this message.
MessageReplyToGroupIdThe Id of the group to send replies to for this message.
MessageSettledWhether this message is settled.
MessageSubjectThe subject of this message.
MessageToThe address of the node which this message is intended for.
MessageTTLThe time-to-live value for this message.
MessageUserIdThe identity of the user responsible for producing this message.
MessageValueThis message's value.
MessageValueTypeThis message's value data type.
OutgoingMessageCountThe number of records in the OutgoingMessage arrays.
OutgoingMessageAbsoluteExpiryTimeThe absolute time at which this message should be considered expired.
OutgoingMessageContentEncodingThe content encoding of this message's data.
OutgoingMessageContentTypeThe content type of this message's data.
OutgoingMessageCorrelationIdThe correlation Id of this message.
OutgoingMessageCreationTimeThe creation time of this message.
OutgoingMessageDeliveryCountHow many previous attempts there have been to deliver this message.
OutgoingMessageDurableWhether this message is durable.
OutgoingMessageFirstAcquirerWhether this message may have been acquired by other links previously.
OutgoingMessageGroupIdThe Id of the group this message belongs to.
OutgoingMessageGroupSequenceThe position of this message within its group.
OutgoingMessageLinkNameThe name of the link this message is associated with.
OutgoingMessageIdThe unique Id of this message.
OutgoingMessagePriorityThe priority of this message.
OutgoingMessageReplyToThe address of the node to send replies to for this message.
OutgoingMessageReplyToGroupIdThe Id of the group to send replies to for this message.
OutgoingMessageSettledWhether this message is settled.
OutgoingMessageSubjectThe subject of this message.
OutgoingMessageToThe address of the node which this message is intended for.
OutgoingMessageTTLThe time-to-live value for this message.
OutgoingMessageUserIdThe identity of the user responsible for producing this message.
OutgoingMessageValueThis message's value.
OutgoingMessageValueTypeThis message's value data type.
PasswordA password to use for SASL authentication.
ReadyToSendIndicates whether the component is ready to send data.
ReceivedMessageAbsoluteExpiryTimeThe absolute time at which this message should be considered expired.
ReceivedMessageContentEncodingThe content encoding of this message's data.
ReceivedMessageContentTypeThe content type of this message's data.
ReceivedMessageCorrelationIdThe correlation Id of this message.
ReceivedMessageCreationTimeThe creation time of this message.
ReceivedMessageDeliveryCountHow many previous attempts there have been to deliver this message.
ReceivedMessageDurableWhether this message is durable.
ReceivedMessageFirstAcquirerWhether this message may have been acquired by other links previously.
ReceivedMessageGroupIdThe Id of the group this message belongs to.
ReceivedMessageGroupSequenceThe position of this message within its group.
ReceivedMessageLinkNameThe name of the link this message is associated with.
ReceivedMessageIdThe unique Id of this message.
ReceivedMessagePriorityThe priority of this message.
ReceivedMessageReplyToThe address of the node to send replies to for this message.
ReceivedMessageReplyToGroupIdThe Id of the group to send replies to for this message.
ReceivedMessageSettledWhether this message is settled.
ReceivedMessageSubjectThe subject of this message.
ReceivedMessageToThe address of the node which this message is intended for.
ReceivedMessageTTLThe time-to-live value for this message.
ReceivedMessageUserIdThe identity of the user responsible for producing this message.
ReceivedMessageValueThis message's value.
ReceivedMessageValueTypeThis message's value data type.
ReceiveModeControls what mode new receiver links are created with.
RemoteHostThe address of the remote host. Domain names are resolved to IP addresses.
RemotePortThe port of the AQMP server (default is 5672). The default port for SSL is 5671.
SessionCountThe number of records in the Session arrays.
SessionIncomingWindowThe incoming window size of this session.
SessionNameThe name of this session.
SessionOutgoingWindowThe outgoing window size of this session.
SSLAcceptServerCertEncodedThe certificate (PEM/base64 encoded).
SSLCertEncodedThe certificate (PEM/base64 encoded).
SSLCertStoreThe name of the certificate store for the client certificate.
SSLCertStorePasswordIf 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.
SSLCertStoreTypeThe type of certificate store for this certificate.
SSLCertSubjectThe subject of the certificate used for client authentication.
SSLEnabledWhether TLS/SSL is enabled.
SSLServerCertEncodedThe certificate (PEM/base64 encoded).
TimeoutA timeout for the component.
UserA username to use for SASL authentication.

Method List


The following is the full list of the methods of the component with short descriptions. Click on the links for further details.

CloseLinkCloses a link.
CloseSessionCloses a session.
ConfigSets or retrieves a configuration setting.
ConnectConnects to a remote host.
CreateReceiverLinkCreates a new receiver link with the given name on the specified session.
CreateSenderLinkCreates a new sender link with the given name on the specified session.
CreateSessionCreates a new session with the given name.
DisconnectDisconnects from the remote host.
DoEventsProcesses events from the internal message queue.
FetchMessageFetches a single message over the specified receiver link.
InterruptInterrupts the current action.
ResetReset the component.
ResetMessageResets the Message properties.
SendMsgSends a message on the specified link.

Event List


The following is the full list of the events fired by the component with short descriptions. Click on the links for further details.

ConnectedFired immediately after a connection completes (or fails).
ConnectionStatusFired to indicate changes in connection state.
DisconnectedFired when a connection is closed.
ErrorInformation about errors during data delivery.
LinkReadyToSendFires when a sender link is ready to send messages.
LogFires once for each log message.
MessageInFires when the component receives a message.
MessageOutFires when the component sends a message.
MessageOutcomeFires when a message's outcome is available.
SSLServerAuthenticationFired after the server presents its certificate to the client.
SSLStatusShows the progress of the secure connection.

Configuration Settings


The following is a list of configuration settings for the component with short descriptions. Click on the links for further details.

AuthorizationIdentityThe value to use as the authorization identity when SASL authentication is used.
DefaultCreditThe amount of credit to create new receiver links with.
DefaultCreditThresholdThe credit threshold to create new receiver links with.
DefaultIncomingWindowThe incoming window size to create new sessions with.
DefaultOutgoingWindowThe outgoing window size to create new sessions with.
DefaultSenderSettleModeThe sender settle mode to create new links with.
GenerateMessageIdWhether a unique message Id should be automatically generated when sending a message.
LogLevelThe level of detail that is logged.
MaxFrameSizeThe maximum frame size.
MaxLinkCountPerSessionThe maximum number of links to restrict new sessions to.
MaxMessageSizeThe maximum message size to restrict new links to.
MaxSessionCountThe maximum number of sessions.
ModifiedDeliveryFailedWhether the sender should treat this transfer as an unsuccessful delivery attempt.
ModifiedMessageAnnotationsThe message annotations that the sender should merge into those already on the message.
ModifiedUndeliverableHereWhether the receiver has indicated that the sender should not attempt to redeliver the message.
ProtocolVersionThe AMQP protocol version to conform to.
RejectErrorConditionThe error condition included with a 'Rejected' delivery outcome.
RejectErrorDescriptionThe error description included with a 'Rejected' delivery outcome.
SenderSettleMode[LinkName]Retrieves the negotiated sender settle mode for the specified link.
SimplifiedJSONFormatWhether to output simplified JSON where possible.
ConnectionTimeoutSets a separate timeout value for establishing a connection.
FirewallAutoDetectTells the component whether or not to automatically detect and use firewall system settings, if available.
FirewallHostName or IP address of firewall (optional).
FirewallPasswordPassword to be used if authentication is to be used when connecting through the firewall.
FirewallPortThe TCP port for the FirewallHost;.
FirewallTypeDetermines the type of firewall to connect through.
FirewallUserA user name if authentication is to be used connecting through a firewall.
KeepAliveIntervalThe retry interval, in milliseconds, to be used when a TCP keep-alive packet is sent and no response is received.
KeepAliveTimeThe inactivity time in milliseconds before a TCP keep-alive packet is sent.
LingerWhen set to True, connections are terminated gracefully.
LingerTimeTime in seconds to have the connection linger.
LocalHostThe name of the local host through which connections are initiated or accepted.
LocalPortThe port in the local host where the component binds.
MaxLineLengthThe maximum amount of data to accumulate when no EOL is found.
MaxTransferRateThe transfer rate limit in bytes per second.
ProxyExceptionsListA semicolon separated list of hosts and IPs to bypass when using a proxy.
TCPKeepAliveDetermines whether or not the keep alive socket option is enabled.
TcpNoDelayWhether or not to delay when sending packets.
UseIPv6Whether to use IPv6.
LogSSLPacketsControls whether SSL packets are logged when using the internal security API.
OpenSSLCADirThe path to a directory containing CA certificates.
OpenSSLCAFileName of the file containing the list of CA's trusted by your application.
OpenSSLCipherListA string that controls the ciphers to be used by SSL.
OpenSSLPrngSeedDataThe data to seed the pseudo random number generator (PRNG).
ReuseSSLSessionDetermines if the SSL session is reused.
SSLCACertsA newline separated list of CA certificate to use during SSL client authentication.
SSLCheckCRLWhether to check the Certificate Revocation List for the server certificate.
SSLCipherStrengthThe minimum cipher strength used for bulk encryption.
SSLEnabledCipherSuitesThe cipher suite to be used in an SSL negotiation.
SSLEnabledProtocolsUsed to enable/disable the supported security protocols.
SSLEnableRenegotiationWhether the renegotiation_info SSL extension is supported.
SSLIncludeCertChainWhether the entire certificate chain is included in the SSLServerAuthentication event.
SSLNegotiatedCipherReturns the negotiated ciphersuite.
SSLNegotiatedCipherStrengthReturns the negotiated ciphersuite strength.
SSLNegotiatedCipherSuiteReturns the negotiated ciphersuite.
SSLNegotiatedKeyExchangeReturns the negotiated key exchange algorithm.
SSLNegotiatedKeyExchangeStrengthReturns the negotiated key exchange algorithm strength.
SSLNegotiatedVersionReturns the negotiated protocol version.
SSLProviderThe name of the security provider to use.
SSLSecurityFlagsFlags that control certificate verification.
SSLServerCACertsA newline separated list of CA certificate to use during SSL server certificate validation.
TLS12SignatureAlgorithmsDefines the allowed TLS 1.2 signature algorithms when UseInternalSecurityAPI is True.
TLS12SupportedGroupsThe supported groups for ECC.
TLS13KeyShareGroupsThe groups for which to pregenerate key shares.
TLS13SignatureAlgorithmsThe allowed certificate signature algorithms.
TLS13SupportedGroupsThe supported groups for (EC)DHE key exchange.
AbsoluteTimeoutDetermines whether timeouts are inactivity timeouts or absolute timeouts.
FirewallDataUsed to send extra data to the firewall.
InBufferSizeThe size in bytes of the incoming queue of the socket.
OutBufferSizeThe size in bytes of the outgoing queue of the socket.
BuildInfoInformation about the product's build.
CodePageThe system code page used for Unicode to Multibyte translations.
LicenseInfoInformation about the current license.
UseInternalSecurityAPITells the component whether or not to use the system security libraries or an internal implementation.

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks IoT 2020 C++ Builder Edition - Version 20.0 [Build 8265]