Skip to main content

Triggers

The ballerinax/solace.jms connector supports event-driven integration through a jms:Listener. When a message arrives on a subscribed queue or topic, the listener dispatches it to your service's onMessage callback automatically; no manual receive loop is required.

Three components work together:

ComponentRole
jms:ListenerConnects to the Solace broker and dispatches messages to the services attached to it.
jms:ServiceDefines the onMessage and onError callbacks invoked when a message arrives or an error occurs.
jms:CallerInjected into onMessage callbacks for manual acknowledgement and session-transacted control.

For action-based operations, see the Action Reference.


Listener​

The jms:Listener establishes the broker connection. Each attached service subscribes to its own queue or topic through the @jms:ServiceConfig annotation.

Configuration​

ListenerConfiguration fields:

FieldTypeDefaultDescription
messageVpnstring"default"Solace message VPN name.
authBasicAuthConfiguration|KerberosConfiguration|OAuth2ConfigurationRequiredAuthentication configuration. See Supporting types.
secureSocketSecureSocket()TLS/SSL configuration.
clientNamestring()Client identifier reported to the broker. A unique name is generated when omitted.
clientDescriptionstring"Ballerina Solace JMS Connector"A description for the application client.
enableDynamicDurablesbooleanfalseAutomatically provision durable destinations that don't already exist on the broker.
directTransportbooleantrueConsume over direct (at-most-once) transport. Set to false for session-transacted services or flow-control tuning.
directOptimizedbooleantrueOptimize the session for direct messaging throughput.
compressionLevelint0ZLIB compression level (0-9, where 0 is no compression).
localhoststring()Local interface IP address to bind for outbound connections.
connectTimeoutdecimal30.0Connection timeout in seconds.
readTimeoutdecimal10.0Read timeout in seconds.
retryConfigRetryConfiguration()Reconnection retry configuration.
transportWindowSizeint()Maximum number of guaranteed messages the broker can have in flight, unacknowledged (1-255). Only applies when directTransport is false.
ackThresholdint60Percentage of transportWindowSize consumed before an automatic acknowledgement is sent (1-75). Only applies when directTransport is false.
ackTimerdecimal()Maximum time in seconds to hold an unacknowledged message before sending an automatic acknowledgement (0.02-1.5). Only applies when directTransport is false.

Important: Session-transacted messaging (ackMode: SESSION_TRANSACTED) requires directTransport: false. A session-transacted commit or rollback is local to a single listener or client session — it can't span multiple client instances, for example a separate producer and consumer used together.

Initializing the listener​

Basic listener with username/password authentication:

import ballerinax/solace.jms;

configurable string solaceJmsUrl = ?;
configurable string solaceJmsUsername = ?;
configurable string solaceJmsPassword = ?;

listener jms:Listener solaceJmsListener = check new (
solaceJmsUrl,
messageVpn = "default",
auth = {username: solaceJmsUsername, password: solaceJmsPassword}
);

Listener with OAuth 2.0 authentication:

import ballerinax/solace.jms;

configurable string solaceJmsUrl = ?;
configurable string solaceJmsIssuer = ?;
configurable string solaceJmsAccessToken = ?;

listener jms:Listener solaceJmsListener = check new (
solaceJmsUrl,
messageVpn = "default",
auth = {issuer: solaceJmsIssuer, accessToken: solaceJmsAccessToken}
);

Service​

A jms:Service is a Ballerina service attached to a jms:Listener. The @jms:ServiceConfig annotation specifies which queue or topic to subscribe to, along with acknowledgement and message-selector settings. A compiler plugin validates every jms:Service at compile time: it must declare exactly one onMessage remote function and at most one onError remote function, neither may be declared as a resource function, and the queue/topic durability fields must be literal-consistent (for example, queueName is required when durability is DURABLE and not allowed when TEMPORARY; subscriberName is required for a DURABLE topic). Diagnostics SOLACE_JMS_101-109 cover service shape; SOLACE_JMS_201-203 cover durability consistency.

@jms:ServiceConfig​

The annotation accepts either a QueueServiceConfiguration or a TopicServiceConfiguration, matching the QueueConfiguration and TopicConfiguration fields described in the Action Reference.

Callback signatures​

FunctionSignatureDescription
onMessageremote function onMessage(record {|*jms:Message; T payload;|} message, jms:Caller caller) returns jms:Error?Invoked when a message is received on the subscribed queue or topic. Narrow T to a specific type to trigger data binding.
onErrorremote function onError(jms:Error err) returns jms:Error?Optional. Invoked when an error occurs during message receipt or data binding.

Note: The caller parameter in onMessage is optional. Omit it for AUTO_ACKNOWLEDGE or DUPS_OK_ACKNOWLEDGE services. Include it (as type jms:Caller) if you need to manually acknowledge messages or manage a session-transacted service.

Full usage example​

import ballerina/log;
import ballerinax/solace.jms;

configurable string solaceJmsUrl = ?;
configurable string solaceJmsUsername = ?;
configurable string solaceJmsPassword = ?;
configurable string solaceJmsQueueName = ?;

listener jms:Listener solaceJmsListener = new (
solaceJmsUrl,
messageVpn = "default",
auth = {username: solaceJmsUsername, password: solaceJmsPassword}
);

type OrderMessage record {|
string orderId;
|};

type Message record {|
*jms:Message;
OrderMessage payload;
|};

@jms:ServiceConfig {
queueName: solaceJmsQueueName,
ackMode: jms:CLIENT_ACKNOWLEDGE
}
service jms:Service on solaceJmsListener {

remote function onMessage(Message message, jms:Caller caller) returns jms:Error? {
do {
log:printInfo("Received order", orderId = message.payload.orderId);
check caller->ack(message);
} on fail error e {
return error("unhandled error", e);
}
}

remote function onError(jms:Error err) returns jms:Error? {
log:printError("Error receiving message", 'error = err);
}
}

Caller​

The jms:Caller is injected into onMessage when the callback declares it as a second parameter. It provides manual control over acknowledgement and session-transacted services.

FunctionSignatureDescription
ackremote function ack(jms:Message message) returns jms:Error?Acknowledges a message. Required when ackMode is CLIENT_ACKNOWLEDGE.
commitremote function 'commit() returns jms:Error?Commits the listener's session-transacted service. Requires ackMode: SESSION_TRANSACTED on the service configuration.
rollbackremote function 'rollback() returns jms:Error?Rolls back the session-transacted service; every message received since the last commit or rollback is redelivered.

Supporting types​

Message​

FieldTypeDescription
payloadanydataMessage payload.
deliveryModeDeliveryModeNON_PERSISTENT (at-most-once) or PERSISTENT (guaranteed, the default).
priorityint?Message priority (0-9).
timeToLivedecimal?Time, in seconds, after which an unconsumed persistent message expires.
messageTypestring?Application-defined message type label.
correlationIdstring?Correlation identifier for request/reply patterns.
replyToDestination?Destination the receiver should reply to.
senderIdstring?Identifier of the sending client. A Solace extension with no standard JMS equivalent.
propertiesmap<Property>?User-defined message properties. Property is boolean|int|byte|float|string, so only JMS scalar property values are allowed (no byte[] or nested maps).
messageIdstring?Receive-only. Broker-assigned message identifier.
timestampint?Receive-only. Broker-side send timestamp in milliseconds.
redeliveredboolean?Receive-only. Whether this delivery is a redelivery.
destinationDestination?Receive-only. The destination the message was received on.
deliveryCountint?Receive-only. Number of times this message has been delivered.
expirationint?Receive-only. Message expiration time in milliseconds.

Destination​

public type Destination Topic|Queue;
TypeFieldsDescription
TopictopicName: stringA Solace topic destination.
QueuequeueName: stringA Solace queue destination.

Enumerations​

EnumMembersDescription
AcknowledgementModeSESSION_TRANSACTED, AUTO_ACKNOWLEDGE, CLIENT_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGEThe JMS session acknowledgement mode.
DeliveryModeNON_PERSISTENT, PERSISTENTAt-most-once versus guaranteed delivery. PERSISTENT is the default.
DurabilityDURABLE, TEMPORARYWhether a subscription is broker-provisioned and named, or created and destroyed with the connection.
ProtocolTLSV1_1, TLSV1_2, TLSV1_3TLS protocol versions accepted by SecureSocket.

Authentication​

TypeFieldsDescription
BasicAuthConfigurationusername: string, password: string?Username/password authentication. username is limited to 189 characters and password to 128 characters.
KerberosConfigurationserviceName: string = "solace", jaasLoginContext: string = "SolaceGSS", mutualAuthentication: boolean = false, jaasConfigFileReloadEnabled: boolean = falseKerberos (GSS) authentication.
OAuth2AccessTokenAuthissuer: string, accessToken: stringOAuth 2.0 authentication with a pre-obtained access token.
OidcIdTokenAuthissuer: string, oidcToken: stringOpenID Connect authentication with an ID token.

OAuth2Configuration is a union of OAuth2AccessTokenAuth and OidcIdTokenAuth.

SecureSocket​

FieldTypeDefaultDescription
trustStoreTrustStore()Truststore used to validate the broker's certificate.
keyStoreKeyStore()Keystore used for mutual TLS.
trustedCommonNamesstring[]()Up to 16 common names accepted in the broker's certificate.
excludedProtocolsProtocol[][]TLS protocol versions to exclude.
cipherSuitesSslCipherSuite[]()Allowed cipher suites. Each entry must be an SslCipherSuite value, for example ECDHE_RSA_AES256_CBC_SHA384.
validationrecord {|boolean enabled = true; boolean validateDate = true; boolean validateHostname = true;|}all trueCertificate validation controls.

TrustStore fields: location: string, password: string, format: JKS|PKCS12 = JKS. KeyStore adds keyPassword?: string and keyAlias?: string.

RetryConfiguration​

FieldTypeDefaultDescription
connectRetriesint0Number of times to retry the initial connection attempt.
connectRetriesPerHostint0Number of retries per host when multiple hosts are configured.
reconnectRetriesint3Number of times to retry reconnecting after the session goes down.
reconnectRetryWaitdecimal3.0Delay in seconds between reconnection attempts.

Errors​

TypeDescription
ErrorThe single, flat error type (distinct error) raised by every client, listener, and caller operation. The connector has no error sub-hierarchy.