Guaranteed Message Flows in the Solace JCSMP API
For a client application using the Solace JCSMP API to publish Guaranteed messages to or consume Guaranteed messages from a Solace event broker, it must create one or more flows within a session. A flow is an API object that allows applications to send or receive Guaranteed messages.
A subscriber flow allows applications to receive Guaranteed messages from an endpoint, such as a queue. Unless otherwise noted, references to flows are to subscriber flows.
Clients also use flows when they publish Guaranteed messages. For the Solace JCSMP API, a producer flow is automatically established at the beginning of a session. This allows the client to send persistent messages at any time while the session remains active. For more information, see Publishing Guaranteed Messages in the Solace JCSMP API.
To create a flow receiver, use the com.solacesystems.jcsmp.FlowReceiver interface, which can be instantiated using the createFlow() method. The following code snippet shows a simple example of a FlowReceiver implementation:
final FlowReceiver cons = session.createFlow(new XMLMessageListener() {
@Override
public void onReceive(BytesXMLMessage msg) {
if (msg instanceof TextMessage) {
System.out.printf("TextMessage received: '%s'%n", ((TextMessage) msg).getText());
} else {
System.out.println("Message received.");
}
System.out.printf("Message Dump:%n%s%n", msg.dump());
// When the ack mode is set to SUPPORTED_MESSAGE_ACK_CLIENT,
// guaranteed delivery messages are acknowledged after processing
msg.ackMessage();
latch.countDown(); // unblock main thread
}
});
Browsers
A browser allows client applications to look at messages spooled on queues from oldest to newest without removing them. After messages are browsed, they can still be received by consumers over Flows.
It is also possible to use a browser to look at messages and selectively remove them from the queue. Removed messages can no longer be consumed.
In the Solace JCSMP API, browsers are objects. To create a browser object, use the com.solacesystems.jcsmp.Browser interface, which can be instantiated using the createBrowser() method.
Browser myBrowser = session.createBrowser(browser_properties);