Skip to main content

Triggers

The ballerinax/solace connector supports event-driven integration through a polling-based listener. When messages arrive on a subscribed queue or topic, the listener dispatches them to your service's onMessage callback automatically; no manual receive loop required.

Three components work together:

ComponentRole
solace:ListenerConnects to the Solace broker and polls for messages, dispatching them to attached services.
solace:ServiceDefines the onMessage and onError callbacks invoked when messages arrive or errors occur.
solace:CallerInjected into onMessage callbacks for manual acknowledgement and transaction control.

For action-based record operations, see the Action Reference.


Listener

The solace:Listener establishes the connection and manages event subscriptions.

Configuration

The listener supports the following connection strategies:

Config TypeDescription
ListenerConfigurationConnection configuration for the Solace listener. Subscription details are specified on each service via the @ServiceConfig annotation.

ListenerConfiguration fields:

FieldTypeDefaultDescription
messageVpnstring"default"Solace Message VPN name.
authBasicAuthConfig|KerberosConfig|OAuth2Config()Authentication configuration.
transactedbooleanfalseEnable transacted session for commit/rollback in service callbacks. When true, directTransport must also be set to false.
secureSocketSecureSocket()TLS/SSL configuration.
clientIdstring()Optional client identifier.
enableDynamicDurablesbooleanfalseAllow dynamic creation of durable endpoints.
connectTimeoutdecimal30.0Connection timeout in seconds.
readTimeoutdecimal10.0Read timeout in seconds.
retryConfigRetryConfig()Reconnection retry configuration.
compressionLevelint0ZLIB compression level (0–9, where 0 is no compression).
directTransportbooleantrueUse direct (at-most-once) delivery when true. Set to false for guaranteed (persistent) delivery and when using transacted sessions.
directOptimizedbooleantrueOptimize message delivery in direct transport mode. Only effective when directTransport is true.
clientDescriptionstring"JNDI"A description for the application client.
allowDuplicateClientIdbooleanfalseAllow the same client ID to be used across multiple connections simultaneously.
localhoststring()Local interface IP address to bind for outbound connections.

Initializing the listener

Basic listener with username/password authentication:

import ballerinax/solace;

configurable string solaceUrl = ?;
configurable string username = ?;
configurable string password = ?;

listener solace:Listener solaceListener = check new (
url = solaceUrl,
messageVpn = "default",
auth = {username: username, password: password}
);

Listener with OAuth 2.0 authentication:

import ballerinax/solace;

configurable string solaceUrl = ?;
configurable string issuer = ?;
configurable string accessToken = ?;

listener solace:Listener solaceListener = check new (
url = solaceUrl,
messageVpn = "default",
auth = {issuer: issuer, accessToken: accessToken}
);

Service

A solace:Service is a Ballerina service attached to a solace:Listener. It uses the @solace:ServiceConfig annotation to specify which queue or topic to subscribe to, along with polling and acknowledgement settings. The service implements onMessage and optionally onError callbacks.

Callback signatures

FunctionSignatureDescription
onMessageremote function onMessage(solace:Message message) returns error?Invoked when a message is received on the subscribed queue or topic. Optionally accepts a solace:Caller as a second parameter for manual acknowledgement or transaction control.
onErrorremote function onError(solace:Error err) returns error?Invoked when an error occurs during message receipt or data binding.
note

The onMessage callback can optionally accept a solace:Caller as a second parameter (e.g., remote function onMessage(solace:Message message, solace:Caller caller)) for manual acknowledgement in CLIENT_ACKNOWLEDGE mode or transaction control in SESSION_TRANSACTED mode.

Full usage example

import ballerina/log;
import ballerinax/solace;

configurable string solaceUrl = ?;
configurable string username = ?;
configurable string password = ?;

listener solace:Listener solaceListener = new (
url = solaceUrl,
messageVpn = "default",
auth = {username: username, password: password}
);

@solace:ServiceConfig {
queueName: "my-queue",
pollingInterval: 2,
receiveTimeout: 1
}
service on solaceListener {
remote function onMessage(solace:Message message) returns error? {
log:printInfo("Received message", payload = message.payload.toString());
}

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

The @solace:ServiceConfig annotation accepts either queue-based (queueName) or topic-based (topicName, consumerType, subscriberName) subscription configurations, along with pollingInterval, receiveTimeout, sessionAckMode, messageSelector, and noLocal fields.


Supporting types

Message

FieldTypeDescription
payloadanydataMessage payload; supports string, byte[], xml, json, record, and map types.
correlationIdstring?Optional correlation identifier for request/reply patterns.
replyToDestination?Optional reply-to destination (Topic or Queue).
propertiesmap<Property>?Optional user-defined properties (boolean, int, byte, float, or string values).
messageIdstring?Unique message identifier.
timestampint?Message timestamp in milliseconds.
destinationDestination?The destination this message was sent to or received from.
deliveryModeint?JMS delivery mode value.
redeliveredboolean?Whether this message is a redelivery.
jmsTypestring?JMS type header value.
expirationint?Message expiration time in milliseconds.
priorityint?Message priority (0–9).

Caller

FieldTypeDescription
acknowledgeremote functionAcknowledges a received message (for CLIENT_ACKNOWLEDGE mode).
commitremote functionCommits the current transacted session.
rollbackremote functionRolls back the current transacted session; messages will be redelivered.