IPWorks IoT 2020 Python Edition

Questions / Feedback?

STOMP Class

Properties   Methods   Events   Configuration Settings   Errors  

A simple but powerful STOMP client implementation.

Syntax

class ipworksiot.STOMP

Remarks

The STOMP class provides an easy-to-use STOMP client implementation that supports STOMP versions 1.1 and 1.2. The class supports both plaintext and TLS-enabled connections over TCP.

Connecting

Connecting to a STOMP server is easy; in the simplest case just call the connect method, passing the server's hostname and port number.

When connecting to a STOMP server, the class sends information from the following properties, if populated:

In addition to the above properties, the following configuration settings can be set before connecting (though in most cases this is not necessary):

  • SupportedVersions: Controls which STOMP versions the class advertises support for.
  • VirtualHost: Controls the virtual host to connect to. If left empty (default), the value from remote_host is used.

Subscriptions & Receiving Messages

The subscribe and unsubscribe methods are used to subscribe to and unsubscribe from message destinations on the server.

When subscribe is called, it will return a subscription Id. To unsubscribe, pass this subscription Id to the unsubscribe method.

After subscribing to a message destination, any messages received will cause the on_message_in event to fire.

Basic Subscriptions Example

stomp1.OnMessageIn += (s, e) => {
  Console.WriteLine("Received message from destination '" + e.Destination + "':");
  Console.WriteLine(e.Data);
};

string subId = stomp1.Subscribe("test/a/b", false);
// Some time later...
stomp1.Unsubscribe(subId);

Refer to subscribe, unsubscribe, and on_message_in for more information about subscriptions and receiving messages.

Sending Messages

To send messages, use the send_message and send_data methods. send_message is used to send messages with string payloads, while send_data is used to send messages with binary payloads.

Send String Message Example

stomp1.SendMessage("test/a/b", "Hello, world!");

Send Binary Message Example

byte[] fileContent = File.ReadAllBytes("C:\test\stuff.dat");
stomp1.SendData("test/a/b", fileContent);

Refer to send_message and send_data for more information about sending messages.

Using Transactions

STOMP transactions are used to group messages together for processing on the server. Messages sent as part of a transaction will not be delivered by the server until the transaction is committed. If the transaction is aborted, the server will discard the messages without attempting to deliver them.

Basic Transaction Example

// Open a new transaction.
stomp1.BeginTransaction("txn1");
// Set the Transaction property to make sure that messages are sent as part of the transaction.
stomp1.Transaction = "txn1";

stomp1.SendMessage("test/a/b", "Hello, world!");
stomp1.SendMessage("test/a/b", "This is a test.");
stomp1.SendMessage("test/a/b", "Another test!");

// At this point, none of the messages sent above would have been delivered to any clients
// subscribed to the "test/a/b" destination yet, because the transaction is still open.

// If we close and commit the transaction, the server will then deliver the messages to subscribers,
// queue them, or process them in another manner; the behavior is server-dependent.
stomp1.CommitTransaction("txn1");

// Or, the transaction can be aborted, in which case the server will discard the messages
// without delivering them to the subscribers.
//stomp1.AbortTransaction("txn1");

// Reset (or change) the Transaction property after committing or aborting a transaction
// so that future messages are not associated with the previous transaction.
stomp1.Transaction = "";

Refer to begin_transaction for more information about using transactions.

Property List


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

connectedTriggers a connection or disconnection.
content_typeThe content type of the outgoing message.
firewall_auto_detectThis property tells the class whether or not to automatically detect and use firewall system settings, if available.
firewall_typeThis property determines the type of firewall to connect through.
firewall_hostThis property contains the name or IP address of firewall (optional).
firewall_passwordThis property contains a password if authentication is to be used when connecting through the firewall.
firewall_portThis property contains the TCP port for the firewall Host .
firewall_userThis property contains a user name if authentication is to be used connecting through a firewall.
header_countThe number of records in the Header arrays.
header_keyThis header's key.
header_valueThis header's value.
incoming_heartbeatSpecifies the server-to-class heartbeat timing.
local_hostThe name of the local host or user-assigned IP interface through which connections are initiated or accepted.
local_portThe TCP port in the local host where the class binds.
outgoing_heartbeatSpecifies the class-to-server heartbeat timing.
parsed_header_countThe number of records in the ParsedHeader arrays.
parsed_header_keyThis header's key.
parsed_header_valueThis header's value.
passwordA password if authentication is to be used.
ready_to_sendIndicates whether the class is ready to send data.
remote_hostThe address of the remote host. Domain names are resolved to IP addresses.
remote_portThe port of the STOMP server (default is 61613). The default port for SSL is 61612.
request_receiptsWhether the class should request that the server provide message receipts.
ssl_accept_server_cert_encodedThe certificate (PEM/base64 encoded).
ssl_cert_encodedThe certificate (PEM/base64 encoded).
ssl_cert_storeThe name of the certificate store for the client certificate.
ssl_cert_store_passwordIf 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.
ssl_cert_store_typeThe type of certificate store for this certificate.
ssl_cert_subjectThe subject of the certificate used for client authentication.
ssl_enabledWhether TLS/SSL is enabled.
ssl_server_cert_encodedThe certificate (PEM/base64 encoded).
subscription_countThe number of records in the Subscription arrays.
subscription_destinationThe destination on the server that this subscription is associated with.
subscription_idThis subscription's unique Id.
timeoutA timeout for the class.
transaction_idSpecifies the Id of the transaction that outgoing messages are associated with.
userA username if authentication is to be used.

Method List


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

abort_transactionAborts an existing transaction.
add_headerAdds a custom header to send with outgoing messages.
begin_transactionBegins a new transaction.
commit_transactionCommits an existing transaction.
configSets or retrieves a configuration setting.
connectConnects to the remote host.
disconnectDisconnects from the remote host.
do_eventsProcesses events from the internal message queue.
interruptInterrupt the current action and disconnects from the remote host.
resetReset the class.
reset_headersClear the user-defined headers collection.
send_dataPublishes a message with a raw data payload.
send_messagePublishes a message with a string payload.
subscribeSubscribes to a message destination on the server.
unsubscribeRemoves an existing subscription.

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.

on_connectedFired immediately after a connection completes (or fails).
on_connection_statusFired to indicate changes in connection state.
on_disconnectedFired when a connection is closed.
on_errorFired when a class or protocol error occurs.
on_logFired once for each log message.
on_message_inFired when a message has been received.
on_message_outFired after a message has been sent.
on_ready_to_sendFired when the class is ready to send data.
on_receipt_inFires when the class receives a receipt from the server.
on_receipt_outFires when the class sends a STOMP frame that includes a 'receipt' header.
on_ssl_server_authenticationFired after the server presents its certificate to the client.
on_ssl_statusShows the progress of the secure connection.
on_subscribedFired when the class has subscribed to a message destination on the server.
on_unsubscribedFired when the class has unsubscribed from a message destination on the server.

Configuration Settings


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

AckTransactionIdThe transaction Id to include when sending a message acknowledgment.
CollapseHeadersWhether the class should collapse headers on incoming messages.
ErrorHeadersRaw headers from a STOMP 'ERROR' frame.
LogLevelThe level of detail that is logged.
OpenTransactionsA comma-separated list of currently open transactions.
ProtocolVersionThe agreed-upon STOMP protocol version that the class is using.
RequestAckReceiptsWhether the class should request receipts for any message acknowledgments that are sent.
RequestSubscriptionReceiptsWhether the class should request receipts when sending subscribe and unsubscribe requests.
RequestTransactionReceiptsWhether the class should request receipts when sending begin, commit, and abort transaction requests.
SendCustomFrameSends a frame constructed using the supplied hex byte string.
ServerInfoInformation about the currently connected server.
SessionIdThe server-assigned session Id.
SupportedVersionsWhich STOMP protocol versions the class should advertise support for when connecting.
VirtualHostThe virtual host to connect to.
ConnectionTimeoutSets a separate timeout value for establishing a connection.
FirewallAutoDetectTells the class 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 class 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.
SSLCACertFilePathsThe paths to CA certificate files on Unix/Linux.
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.
SSLNegotiatedProtocolReturns 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.
ProcessIdleEventsWhether the class uses its internal event loop to process events when the main thread is idle.
SelectWaitMillisThe length of time in milliseconds the class will wait when DoEvents is called if there are no events to process.
UseInternalSecurityAPITells the class 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 Python Edition - Version 20.0 [Build 8162]