Creating Flows
To receive Guaranteed messages, client must create a consumer flow within a session, and bind that flow to an endpoint on a Solace PubSub+ event broker that messages are published or attracted to. One or more flows can be created in a session.
A flow is an API object that allows a client to receive Guaranteed messages from an endpoint. A maximum of 1,000 flows can be created in a session.
JavaScript and Node.js APIs use the concept of a MessageConsumer
to represent a flow.
To create a flow in a connected session, call the appropriate create flow method or function listed and provide the following:
- Flow properties
When a flow is created, flow properties must be provided. The table Important Flow (Message Consumer) Properties lists many important flow properties that are common to the messaging APIs. For a complete list of required flow properties, valid syntax and parameters, and default values, refer to the PubSub+ Messaging APIs for the appropriate messaging API.
JavaScript and Node.js APIs use
solace.MessageConsumerProperties
for flow properties. - Endpoint to bind to
This argument is only required for the Java RTO and .NET APIs. For the Java, JavaScript, Node.js, and C APIs, the endpoint to bind to is provided in the flow properties.
- Topic subscription
The Topic subscription to use when binding to a Topic Endpoint. This argument is only required for the Java RTO and .NET APIs. For the Java, JavaScript, Node.js, and C APIs, the Topic subscription is provided in the flow properties.
- Message handlers
For each of the messaging APIs, a callback for handling received messages on the flow must be provided:
- For JCSMP, pass in an
XMLMessageListener
callback interface to receive messages asynchronously. If noXMLMessageListener
is set (that is, the message listener tonull
), messages are received synchronously. - For the Java RTO API, pass in a
MessageCallback
. - For the C API, pass in a pointer to a structure that provides information on callback functions for received messages and events.
- For the .NET API, pass in a
messageEventHandler
. - For the JavaScript and Node.js APIs, define a listener to the
solace.MessageConsumerEventName.MESSAGE
event.
- For JCSMP, pass in an
- Flow event handlers
If the Active flow Indication property is enabled, you must also provide a flow event callback, event listener, or handler so that events indicating whether a client has an active flow to the exclusive queue, can be handled. Refer to Active Flow Indication.
- Endpoint properties when binding to a temporary endpoint
For a list of the endpoint properties and the default values used, refer to the PubSub+ Messaging APIs for the appropriate messaging API.
Consumer flows are not used to receive Direct messages because Direct messages are received directly through the session interface.
JCSMP
To receive messages on a logical flow, a client application must first acquire a FlowReceiver
instance. Then to start receiving messages on the flow, call FlowReceiver.start()
. To stop receiving messages on the flow, call the stop()
method.
The FlowReceiver
is in an opened state until the FlowReceiver.close()
method is called.
PubSub+ Messaging API | Call |
---|---|
JCSMP |
Once a When using a synchronous receive mode, after
|
Java RTO |
SessionHandle.createFlowForHandle(...) |
C |
solClient_session_createFlow(...) |
.NET |
ISession.createFlow(...) |
JavaScript and Node.js |
solace.Session.createMessageConsumer(...) |
Property | Description |
---|---|
Active Flow Indication |
When enabled, this property enables active flow events to be generated to indicate to a client bound to an exclusive queue whether it has an active flow (that is, a flow in which messages are being delivered). For more information, refer to Active Flow Indication. |
Message Acknowledgment Mode |
Sets whether the API automatically generates an application-level acknowledgment for each received message (the default), or if the client must explicitly acknowledge each received message. When the client provides an acknowledgment, the corresponding spooled message can be removed from the endpoint on the event broker. This parameter does not affect the Guaranteed message window. For more information on message acknowledgment modes, refer to Acknowledging Messages Received by Clients. |
Message Acknowledgment Threshold |
The threshold for sending a windowed message acknowledgment (set as a percentage of the window size). This affects the flow-control window acknowledgment. The API sends a transport acknowledgment every N messages. N is calculated as this percentage of the flow window size if the endpoint's max-delivered-unacked-msgs-per-flow setting at bind time is greater than or equal to the transport window size. Otherwise, N is calculated as this percentage of the endpoint's max-delivered-unacked-msgs-per-flow setting at bind time. This threshold does not control application-level message acknowledgments. |
Message Acknowledgment Timer |
The maximum amount of time (in milliseconds) that can pass before an acknowledgment for Guaranteed messages received through the flow must be sent. This parameter is used in a situation where Guaranteed messages have been received, but the message acknowledgment window threshold has not been met. |
Endpoint (JCSMP, Java RTO, C, .NET APIs) |
The endpoint to bind to. |
Queue Descriptor (JavaScript and Node.js APIs) |
Defines the queue from which to consume (bind to):
|
Queue Properties (JavaScript and Node.js APIs) |
The properties of the remote queue.
|
Topic Subscription |
If binding to a topic endpoint, the topic subscription to set on the endpoint. |
Selector |
An optional SQL-92 selector to use for the selection of messages for delivery (refer to Using Selectors). |
Guaranteed Message Window Size |
The maximum number of messages that can be received through the flow before the API must send an acknowledgment to the event broker that the messages were received. For more information, refer to Acknowledging Messages Received by Clients. The Guaranteed message window size should not exceed the max-delivered-unacked-msgs-per-flow value that is set for a queue provisioned on the event broker, otherwise messages delivered to the API will not be acknowledged until the message acknowledgment time value is exceeded. |
Start State |
Whether a flow should be in a started state when it is created. In started state, a flow can begin to receive messages immediately. |
No Local |
When enabled, messages published on the session cannot be received through in an active flow created in the same session, even if the subscription matches the topic of the published message. For more information, see No Local Delivery. |
Reconnect Retry Count |
The maximum number of flow reconnect attempts to make after an error response with reason replay started or service unavailable is received. For more information, refer to Flow Reconnect. |
Reconnect Retry Interval |
The wait time between flow reconnect attempts. For more information refer to Flow Reconnect. |
Related Samples
For an example of how to configure flow properties and bind to a flow, refer to the SimpleFlowToQueue
and SimpleFlowToTopic
samples for the appropriate messaging APIs.
For the JavaScript and Node.js APIs, refer to the QueueConsumer
and DTEConsumer
samples.
Active Flow Indication
If a queue has an exclusive access type (refer to Defining Endpoint Properties), multiple clients can bind to the queue, but only one client at a time can actively receive messages from it. Therefore, when a client creates a flow and binds to an exclusive queue, the flow might not be active for the client if other clients are bound to the queue.
If the active flow Indication property is enabled, a flow active event is returned to the client when its bound flow becomes the active flow. The client also receives a flow inactive event whenever it loses an active flow (for example, if the flow disconnects).
The client must provide the following when the flow is created:
- When using the Java or Java RTO APIs, pass in a
FlowEventHandler
to use to handle the flow active and flow inactive events. - When using the C API, pass in a pointer to the
functInfo_p
structure to provide information on the callback function to use for received flow active and flow inactive events. - When using the .NET API, pass in a
flowEventHandler
to use to handle the flow active and flow inactive events.
The active flow indication property is ignored when a flow binds to a non-exclusive queue, unless that queue is partitioned. In the case of a partitioned queue, clients logically bind to the parent (non-exclusive) queue, but the event broker actually binds them to a partition (exclusive) queue. Because of this, the active flow Indication can be used with partitioned queues.
No Local Delivery
It is possible for a client to publish non‑persistent or persistent messages to a topic, and if the same client has a matching topic subscription, it can receive them on an active flow on the same session. To prevent a client from receiving any non‑persistent or persistent messages that it has published, the no local property can be used for the flow that the client uses to bind an exclusive queue (that is, a queue that only permits a single bound client to receive messages) or a topic endpoint, and that flow must be the active flow for the endpoint. (The no local property is ignored when the flow binds to a non‑exclusive queue.) For more information on access types, refer to refer to Defining Endpoint Properties.
- The no local property only prevents messages published by a client from being spooled for that same client if it has established an active flow at the same time. If the client does not have an active flow established, messages published to the topic that it subscribes to can still be spooled.
- The no local property can also be enabled for a session. When enabled for a session, the no local property only affects the delivery of Direct messages to the client on the same session that the messages were published on. It does not affect the delivery of non-persistent or persistent messages. (For more information, see Enabling No Local Delivery for a Session.)
When the no local property is enabled only for the session or only for the flow, it is possible for the event broker to change the delivery mode of a published message so that it could still be delivered to its publishing client. For example, if a client publishes a message to topic “A”, the message cannot be delivered as a Direct message to that client when no local is enabled for the session, but if no local is not enabled for a flow bound to a topic endpoint with the topic subscription “A”, the message could be delivered to that client on the flow as a non-persistent message.
For information on how messages’ delivery modes can be automatically modified when a topic match occurs, see Topic Matching and Message Delivery Modes.
PubSub+ Messaging API | Property |
---|---|
JCSMP |
ConsumerFlowProperties. |
Java RTO |
FlowHandle.PROPERTIES.NO_LOCAL |
C |
SOLCLIENT_FLOW_PROP_NO_LOCAL |
.NET |
FlowProperties.NoLocal |
JavaScript and Node.js |
solace.MessageConsumerProperties.noLocal |
Flow Reconnect
When flow reconnect is enabled, all APIs automatically attempt to reconnect a flow when an error response is received as long as the reason given in the error response string is one of the following:
- Replay started
- Service unavailable—Indicates that either the queue or topic endpoint was shutdown or deleted, or assured delivery services on the broker have been disabled.
In addition, when one of these errors is reported they are accompanied by a RECONNECTING
event as defined in each API. If the reconnect is successful, the API generates a RECONNECTED
event. If the reconnect fails, then the appropriate DOWN
error event occurs.
This behavior applies only to established flows. If an initial bind is rejected by the message broker for any reason, then it is reported as a bind failed event and no retry is attempted.
Flow reconnect is supported and enabled by default in the following API versions:
- JCSMP 10.7.0+
- Java RTO API 7.12.0+
- C API 7.13.0+
- .NET API 10.8.0+
- JavaScript and Node.js API 10.4.0+
While enabled, all APIs attempt to reconnect flows every three seconds indefinitely.
You can configure the maximum number of flow reconnect attempts, as well as the interval between attempts by providing the appropriate properties when the flow is created (see the tables below).
To disable flow reconnect, set the reconnect retry count to 0.
PubSub+ Messaging API | Property |
---|---|
JCSMP |
ConsumerFlowProperties.setReconnectTries |
Java RTO |
FlowHandle.PROPERTIES.MAX_RECONNECT_TRIES |
C |
SOLCLIENT_FLOW_PROP_MAX_RECONNECT_TRIES |
.NET |
FlowProperties.ReconnectTries |
JavaScript and Node.js |
solace.MessageConsumerProperties.reconnectAttempts |
PubSub+ Messaging API | Property |
---|---|
JCSMP |
ConsumerFlowProperties.setReconnectRetryIntervalInMsecs |
Java RTO |
FlowHandle.PROPERTIES.RECONNECT_RETRY_INTERVAL_MS |
C |
SOLCLIENT_FLOW_PROP_RECONNECT_RETRY_INTERVAL_MS |
.NET |
FlowProperties.ReconnectRetryInterval |
JavaScript and Node.js |
solace.MessageConsumerProperties.reconnectIntervalInMsecs |