IPWorks MQ 2020 Kotlin Edition

Questions / Feedback?

AMQPClassic Component

Properties   Methods   Events   Configuration Settings   Errors  

An easy-to-use AMQP 0.9.1 client implementation, with support for RabbitMQ extensions.

Syntax

ipworksmq.Amqpclassic

Remarks

The AMQPClassic component provides an easy-to-use AMQP 0.9.1 client implementation, and it also supports certain RabbitMQ extensions to the AMQP 0.9.1 specification. The component supports both plaintext and TLS-enabled connections over TCP.

Connecting

The AMQP 0.9.1 transport protocol has two layers: an overall connection between the client and server, and one or more channels running over that connection.

The component implements both layers, so the first step is to initiate the overall connection. Set the AuthScheme, User, Password, SSLEnabled, and VirtualHost properties if necessary, then call the Connect method, passing it the server's hostname and port number. (If the server in question is not running RabbitMQ, disabling the RabbitMQCompatible configuration setting before connecting is also recommended.)

The next step is to create at least one channel, which can be accomplished by using the CreateChannel method. The component allows creating any number of channels, up to the limit specified by the MaxChannelCount configuration setting.

Connecting and Creating a Channel

// The examples in this documentation use a RabbitMQ server, which requires SASL Plain auth.
amqpc1.AuthScheme = AmqpclassicAuthSchemes.smSASLPlain;
amqpc1.User = "guest";
amqpc1.Password = "guest";
amqpc1.SSLEnabled = true;
amqpc1.Connect("amqpclassic.test-server.com", 5671);
amqpc1.CreateChannel("channel");

Once the component has connected to the server, and one or more channels have been opened, the component can begin manipulating exchanges and queues, publishing messages, and creating consumers.

Note that most AMQP 0.9.1 operations can themselves vary in their complexity. The examples below are intentionally simple for the sake of clarity and brevity, but links are provided for many other parts of the component's API where more detail can be found.

Declaring Exchanges

The DeclareExchange method is used to declare (i.e., create, or verify the existence of) exchanges on the server. While all AMQP servers provide a default, direct-type exchange that all queues are bound to automatically (using their name as the routing key), more complex use-cases will often require creating additional exchanges of varying types.

Declaring an Exchange

// Declare a direct-type exchange.
amqpc1.DeclareExchange("channel", "MyExchange", "direct", false, false, false, false);

Exchanges can also be deleted using the DeleteExchange method.

Declaring Queues

The DeclareQueue method is used to declare (i.e., create, or verify the existence of) queues on the server. Unlike with exchanges, the server does not provide any queues by default, so declaring a queue is always necessary (unless one has already been created by another client, or configured ahead-of-time on the server itself).

Declaring a Queue

// Declare a queue.
amqpc1.DeclareQueue("channel", "MyQueue", false, false, false, false, false);

Queues may also be deleted or purged using the DeleteQueue and PurgeQueue methods.

Binding Queues to Exchanges

The BindQueue method is used to bind a queue to an exchange. Exchanges use the information held by their queue bindings to determine which messages to forward to which queues.

Note that all AMQP 0.9.1 servers automatically bind all queues to their default exchange (which is always a direct exchange with no name) using each queue's name as the binding's routing key. This makes it easy to send a message to a specific queue without having to declare bindings; just call PublishMessage, pass empty string for ExchangeName, and the name of the desired queue for RoutingKey.

Binding a Queue to an Exchange

// Bind a queue to an exchange. Messages will only be delivered to the queue if their routing key is "MyRoutingKey".
amqpc1.BindQueue("channel", "MyQueue", "MyExchange", "MyRoutingKey", false);

Queues can also be unbound from exchanges using the UnbindQueue method.

Publishing Messages

To publish a message, populate the Message property's fields, and then call the PublishMessage method.

Publishing a Message

amqpc1.Message.Body = "Hello, world!";

// Publish a message to the server's default (no-name) exchange, using the name of a specific queue as the routing key.
amqpc1.PublishMessage("channel", "", "MyQueue", false, false);

// Publish a message to the "MyExchange" exchange, using the routing key "MyRoutingKey".
amqpc1.PublishMessage("channel", "MyExchange", "MyRoutingKey", false, false);

Note that outgoing messages may be handled differently by the server if the channel they are sent over is in transaction or (for RabbitMQ only) "publish confirmations" mode. Refer to the EnableTransactionMode and EnablePublishConfirms methods for more information.

Receiving Messages

There are two possible ways for the component to receive a message:

  • Messages can be asynchronously pushed to the component from the server. At any point in time, the server may push a message to the component from a queue that the Consume method has been used to attach a consumer to.
  • Messages can be synchronously pulled from the server by the component. The FetchMessage method is used to attempt to pull (or "fetch") messages from a specific queue.

Regardless of how they are received, all incoming messages cause the ReceivedMessage property's fields to be populated and the MessageIn event to fire.

Receiving a Message

// MessageIn event handler.
amqpc1.OnMessageIn += (s, e) => {
  if (e.MessageCount == -1) {
    // The server pushed a message to us asynchronously due to a consumer we created.
    Console.WriteLine("The server pushed this message to us via consumer '" + e.ConsumerTag + "':");
    Console.WriteLine(amqpc1.ReceivedMessage.Body);
  } else if (e.DeliveryTag > 0) {
    // We pulled a message from a queue with the FetchMessage() method.
    Console.WriteLine("Message successfully pulled:");
    Console.WriteLine(amqpc1.ReceivedMessage.Body);
    Console.WriteLine(e.MessageCount + " messages are still available to pull.");
  } else {
    // We tried to pull a message, but there were none available to pull.
    Console.WriteLine("No messages available to pull.");
  }
};

// Attach a consumer to "MyQueue".
amqpc1.Consume("channel", "MyQueue", "consumerTag", false, true, false, false);

// Or, try to fetch a message from "MyQueue".
amqpc1.FetchMessage("channel", "MyQueue", true);

Note that the MessageIn event always fires if FetchMessage is called successfully, even if there were no messages available to fetch; refer to MessageIn for more information.

Property List


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

ArgumentsA collection of table fields that specify arguments to send to the server when calling certain methods.
AuthSchemeThe authentication scheme to use when connecting.
ChannelsCollection of active channels.
ClientPropertiesA collection of table fields that describe properties of the client.
ConnectedTriggers a connection or disconnection.
FirewallA set of properties related to firewall access.
HeartbeatThe heartbeat timeout value.
IncomingMessagesCollection of incoming messages which are waiting for acknowledgement.
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.
MessageThe message to send.
OutgoingMessagesCollection of outgoing messages which are waiting for acknowledgement.
PasswordA password to use for SASL authentication.
QueueMessageCountThe message count returned by various queue operations.
ReceivedMessageThe last message received.
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.
ServerPropertiesA collection of table fields that describe properties of the server.
SSLAcceptServerCertInstructs the component to unconditionally accept the server certificate that matches the supplied certificate.
SSLCertThe certificate to be used during SSL negotiation.
SSLEnabledWhether TLS/SSL is enabled.
SSLServerCertThe server certificate for the last established connection.
TimeoutA timeout for the component.
UserA username to use for SASL authentication.
VirtualHostThe virtual host to connect to.

Method List


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

BindQueueBinds a queue to an exchange.
CancelConsumeCancels an existing consumer.
CloseChannelCloses a channel.
CommitTransactionCommits the current transaction for a channel.
ConfigSets or retrieves a configuration setting.
ConnectConnects to a remote host.
ConsumeStarts a new consumer for a given queue.
CreateChannelCreates a new channel.
DeclareExchangeVerifies that an exchange exists, potentially creating it if necessary.
DeclareQueueVerifies that a queue exists, potentially creating it if necessary.
DeleteExchangeDeletes an exchange.
DeleteQueueDeletes a queue.
DisconnectDisconnects from the remote host.
DoEventsProcesses events from the internal message queue.
EnablePublishConfirmsEnables publish confirmations mode for a channel.
EnableTransactionModeEnables transaction mode for a channel.
FetchMessageAttempts to fetch a message from a given queue.
InterruptInterrupt the current action and disconnects from the remote host.
PublishMessagePublishes a message.
PurgeQueuePurges all messages from a queue.
RecoverRequest that the server redeliver all messages on a given channel that have not been acknowledged.
ResetReset the component.
ResetMessageResets the Message properties.
RollbackTransactionRolls back the current transaction for a channel.
SetChannelAcceptDisables or enables message acceptance for a given channel.
SetQoSRequests a specific quality of service (QoS).
UnbindQueueRemoves a previously-created queue binding.

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.

ChannelReadyToSendFires when a channel is ready to send messages.
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.
LogFires once for each log message.
MessageInFires when a message is received; as well as when an attempt is made to fetch a message from a currently empty queue.
MessageOutFires when a message is published.
MessageReturnedFires if a previously published message is returned by the server due to it being undeliverable.
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.
ConsumerTagThe consumer tag associated with the most recently created consumer.
LocaleThe desired message locale to use.
LocalesThe message locales supported by the server.
LogLevelThe level of detail that is logged.
MaxChannelCountThe maximum number of channels.
MaxFrameSizeThe maximum frame size.
MechanismsThe authentication mechanisms supported by the server.
NackMultipleWhether negative acknowledgments should be cumulative or not.
ProtocolVersionThe AMQP protocol version to conform to.
QueueConsumerCountThe consumer count associated with the most recently created (or verified) queue.
QueueNameThe queue name associated with the most recently created (or verified) queue.
RabbitMQCompatibleWhether to operate in a mode compatible with RabbitMQ.
CloseStreamAfterTransferIf true, the component will close the upload or download stream after the transfer.
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).
FirewallListenerIf true, the component binds to a SOCKS firewall as a server (IPPort only).
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.
UseNTLMv2Whether to use NTLM V2.
LogSSLPacketsControls whether SSL packets are logged when using the internal security API.
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.
SSLContextProtocolThe protocol used when getting an SSLContext instance.
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.
SSLProviderThe name of the security provider to use.
SSLServerCACertsA newline separated list of CA certificate to use during SSL server certificate validation.
SSLTrustManagerFactoryAlgorithmThe algorithm to be used to create a TrustManager through TrustManagerFactory.
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.

Copyright (c) 2021 /n software inc. - All rights reserved.
IPWorks MQ 2020 Kotlin Edition - Version 20.0 [Build 7941]