Guaranteed Message Flows in the PubSub+ JCSMP API
For a client application using the PubSub+ JCSMP API to publish Guaranteed messages to or consume Guaranteed messages from a Solace Transform Processor 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.
Flows are also used when a client publishes Guaranteed messages. For the PubSub+ JCSMP API, a producer flow is created when an XMLMessageProducer
is acquired. Refer to Publishing Guaranteed Messages in the PubSub+ 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 PubSub+ 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);