AMQP Object
An easy-to-use AMQP 1.0 client implementation.
Syntax
Tiot.AMQP
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 MaxSessionCountconfiguration 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.
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
view source
// 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");
The following is the full list of the properties of the component with short descriptions.
AuthScheme
The authentication scheme to use when connecting.
Connected
Triggers a connection or disconnection.
ContainerId
The container Id the component should advertise when connecting.
FetchTimeout
How long the component should wait for a message to be received after FetchMessage is called.
FirewallAutoDetect
This property tells the component 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 component will allow before disconnecting.
IncomingMessageCount
The number of records in the IncomingMessage arrays.
IncomingMessageAbsoluteExpiryTime
The absolute time at which this message should be considered expired.
IncomingMessageContentEncoding
The content encoding of this message's data.
IncomingMessageContentType
The content type of this message's data.
IncomingMessageCorrelationId
The correlation Id of this message.
IncomingMessageCreationTime
The creation time of this message.
IncomingMessageDeliveryCount
How many previous attempts there have been to deliver this message.
IncomingMessageDurable
Whether this message is durable.
IncomingMessageFirstAcquirer
Whether this message may have been acquired by other links previously.
IncomingMessageGroupId
The Id of the group this message belongs to.
IncomingMessageGroupSequence
The position of this message within its group.
IncomingMessageLinkName
The name of the link this message is associated with.
IncomingMessageId
The unique Id of this message.
IncomingMessagePriority
The priority of this message.
IncomingMessageReplyTo
The address of the node to send replies to for this message.
IncomingMessageReplyToGroupId
The Id of the group to send replies to for this message.
IncomingMessageSettled
Whether this message is settled.
IncomingMessageSubject
The subject of this message.
IncomingMessageTo
The address of the node which this message is intended for.
IncomingMessageTTL
The time-to-live value for this message.
IncomingMessageUserId
The identity of the user responsible for producing this message.
IncomingMessageValue
This message's value.
IncomingMessageValueType
This message's value data type.
LinkCount
The number of records in the Link arrays.
LinkAvailable
The number of messages which this link's sender could send if it had credit for them.
LinkChannelName
The channel name this link is using.
LinkCredit
The amount of credit currently available to this link's sender.
LinkDeliveryCount
The current delivery count value for this link.
LinkName
This link's name.
LinkReadyToSend
Whether this link is ready to send a message.
LinkReceiveMode
The receive mode this link is operating in.
LinkRole
The component'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 IPPort 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
The absolute time at which this message should be considered expired.
OutgoingMessageContentEncoding
The content encoding of this message's data.
OutgoingMessageContentType
The content type of this message's data.
OutgoingMessageCorrelationId
The correlation Id of this message.
OutgoingMessageCreationTime
The creation time of this message.
OutgoingMessageDeliveryCount
How many previous attempts there have been to deliver this message.
OutgoingMessageDurable
Whether this message is durable.
OutgoingMessageFirstAcquirer
Whether this message may have been acquired by other links previously.
OutgoingMessageGroupId
The Id of the group this message belongs to.
OutgoingMessageGroupSequence
The position of this message within its group.
OutgoingMessageLinkName
The name of the link this message is associated with.
OutgoingMessageId
The unique Id of this message.
OutgoingMessagePriority
The priority of this message.
OutgoingMessageReplyTo
The address of the node to send replies to for this message.
OutgoingMessageReplyToGroupId
The Id of the group to send replies to for this message.
OutgoingMessageSettled
Whether this message is settled.
OutgoingMessageSubject
The subject of this message.
OutgoingMessageTo
The address of the node which this message is intended for.
OutgoingMessageTTL
The time-to-live value for this message.
OutgoingMessageUserId
The identity of the user responsible for producing this message.
OutgoingMessageValue
This message's value.
OutgoingMessageValueType
This message's value data type.
Password
A password to use for SASL authentication.
ReadyToSend
Indicates whether the component 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
The incoming window size of this session.
SessionName
The name of this session.
SessionOutgoingWindow
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 component.
User
A username to use for SASL authentication.
The following is the full list of the methods of the component with short descriptions.
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 component.
ResetMessage
Resets the Message properties.
SendMessage
Sends a message on the specified link.
The following is the full list of the events fired by the component with short descriptions.
Connected
Fired immediately after a connection completes (or fails).
ConnectionStatus
Fired to indicate changes in connection state.
Disconnected
Fired when a connection is closed.
Error
Information about errors during data delivery.
LinkReadyToSend
Fires when a sender link is ready to send messages.
Log
Fires once for each log message.
MessageIn
Fires when the component receives a message.
MessageOut
Fires when the component sends a message.
MessageOutcome
Fires when a message's outcome is available.
SSLServerAuthentication
Fired after the server presents its certificate to the client.
SSLStatus
Shows the progress of the secure connection.
The following is a list of configuration settings for the component with short descriptions.
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 component 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.
KeepAliveTime
The inactivity time in milliseconds before a TCP keep-alive packet is sent.
KeepAliveInterval
The retry interval, in milliseconds, to be used when a TCP keep-alive packet is sent and no response is received.
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 component 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.
UseIPv6
Whether to use IPv6.
TcpNoDelay
Whether or not to delay when sending packets.
LogSSLPackets
Controls whether SSL packets are logged when using the internal security API.
ReuseSSLSession
Determines if the SSL session is reused.
SSLCipherStrength
The minimum cipher strength used for bulk encryption.
SSLEnabledProtocols
Used to enable/disable the supported security protocols.
SSLIncludeCertChain
Whether the entire certificate chain is included in the SSLServerAuthentication event.
SSLProvider
The name of the security provider to use.
SSLSecurityFlags
Flags that control certificate verification.
SSLEnabledCipherSuites
The cipher suite to be used in an SSL negotiation.
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.
TLS13SupportedGroups
The supported groups for (EC)DHE key exchange.
TLS13SignatureAlgorithms
The allowed certificate signature algorithms.
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).
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.
CodePage
The system code page used for Unicode to Multibyte translations.
UseInternalSecurityAPI
Tells the component whether or not to use the system security libraries or an internal implementation. |