IPWorks IoT 2020 Android Edition

Questions / Feedback?

STOMP Component

Properties   Methods   Events   Configuration Settings   Errors  

A simple but powerful STOMP client implementation.

Syntax

IPWorksIoT.Stomp

Remarks

The STOMP component provides an easy-to-use STOMP client implementation that supports STOMP versions 1.1 and 1.2. The component 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 component 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 component advertises support for.
  • VirtualHost: Controls the virtual host to connect to. If left empty (default), the value from RemoteHost 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 MessageIn 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 MessageIn for more information about subscriptions and receiving messages.

Sending Messages

To send messages, use the SendMessage and SendData methods. SendMessage is used to send messages with string payloads, while SendData 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 SendMessage and SendData 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 BeginTransaction for more information about using transactions.

Property List


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

ConnectedTriggers a connection or disconnection.
ContentTypeThe content type of the outgoing message.
FirewallA set of properties related to firewall access.
HeadersUser-defined headers added to outgoing messages.
IncomingHeartbeatSpecifies the server-to-component heartbeat timing.
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.
OutgoingHeartbeatSpecifies the component-to-server heartbeat timing.
ParsedHeadersHeaders parsed from incoming messages.
PasswordA password if authentication is to be used.
ReadyToSendIndicates whether the component is ready to send data.
RemoteHostThe address of the remote host. Domain names are resolved to IP addresses.
RemotePortThe port of the STOMP server (default is 61613). The default port for SSL is 61612.
RequestReceiptsWhether the component should request that the server provide message receipts.
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.
SubscriptionsCollection of current subscriptions.
TimeoutA timeout for the component.
TransactionIdSpecifies 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 component with short descriptions. Click on the links for further details.

abortTransactionAborts an existing transaction.
addHeaderAdds a custom header to send with outgoing messages.
beginTransactionBegins a new transaction.
commitTransactionCommits an existing transaction.
configSets or retrieves a configuration setting.
connectConnects to the remote host.
disconnectDisconnects from the remote host.
doEventsProcesses events from the internal message queue.
interruptInterrupt the current action and disconnects from the remote host.
resetReset the component.
resetHeadersClear the user-defined headers collection.
sendDataPublishes a message with a raw data payload.
sendMessagePublishes 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 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.
ErrorFired when a component or protocol error occurs.
LogFired once for each log message.
MessageInFired when a message has been received.
MessageOutFired after a message has been sent.
ReadyToSendFired when the component is ready to send data.
ReceiptInFires when the component receives a receipt from the server.
ReceiptOutFires when the component sends a STOMP frame that includes a 'receipt' header.
SSLServerAuthenticationFired after the server presents its certificate to the client.
SSLStatusShows the progress of the secure connection.
SubscribedFired when the component has subscribed to a message destination on the server.
UnsubscribedFired when the component has unsubscribed from a message destination on the server.

Configuration Settings


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

AckTransactionIdThe transaction Id to include when sending a message acknowledgment.
CollapseHeadersWhether the component 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 component is using.
RequestAckReceiptsWhether the component should request receipts for any message acknowledgments that are sent.
RequestSubscriptionReceiptsWhether the component should request receipts when sending subscribe and unsubscribe requests.
RequestTransactionReceiptsWhether the component 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 component should advertise support for when connecting.
VirtualHostThe virtual host to connect to.
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.
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.
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.
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.
BuildInfoInformation about the product's build.
GUIAvailableTells the component whether or not a message loop is available for processing events.
LicenseInfoInformation about the current license.
UseDaemonThreadsWhether threads created by the component are daemon threads.
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 Android Edition - Version 20.0 [Build 8265]