public interface DestinationProducer extends Producer
DestinationProducer provides an interface for applications to
send messages to Destinations.
DestinationProducer instance is
acquired from JCSMPDestinationSession. When acquired successfully,
the instance of DestinationProducer holds a channel (connection)
opened to the appliance. Applications must cache this instance reference, and
close it only when it is no longer required.
Note: The methods defined in this interface are non-thread-safe, except the close()
method, which may be called at any time by any thread.
create[...]
message methods to create an XMLMessage instance. An application must
not cache the created message object based on the assumption that a new
object is returned each time. The JCSMP implementation may choose to reuse
the same message object.
Once the close() method is invoked, the instance of this class
loses its channel connection to the appliance. Any further access, such as
sending messages, causes an exception to be raised. An application can
reacquire an "opened" DestinationProducer by calling JCSMPDestinationSession.getMessageProducer(JCSMPStreamingPublishEventHandler,
Destination defaultDestination) again.
DestinationProducer operates in either blocking or non-blocking
mode. When working in blocking mode, the send() method blocks
until a confirmation of delivery is received by the
DestinationProducer. When a callback handler
JCSMPStreamingPublishEventHandler is passed in while acquiring
DestinationProducer, DestinationProducer operates
in non-blocking mode, also known as streaming publish mode. In other words,
the send() does not block until the appliance acknowledges
delivery. Applications receive notifications regarding error conditions of
delivery through the callback handler
JCSMPStreamingPublishEventHandler.
For increased performance when publishing Persistent or Non-Persistent
messages, a session may be configured to use a sliding window acknowledgement
method (refer to JCSMPProperties for information on configuring
sliding window parameters).
If using a window size greater than 1 for the publisher's sliding window, application designers must take care NOT to use blocking (synchronous) publishing mode, as message publishing operations are blocked until an acknowledgement is received for each message. This acknowledgement might not come in a timely fashion as the window is not filled with a single published message.
Note: During publishing assured delivery messages (
Persistent, Non-Persistent), send() method blocks while the SDK awaits
an acknowledgement from the appliance if the publisher's Guaranteed delivery
acknowledgement window is filled.
JCSMPDestinationSession session = null;
DestinationProducer producer = null;
try {
JCSMPProperties props = new JCSMPProperties();
... // setup properties
session = JCSMPFactory.onlyInstance().createDestinationSession(props);
producer = session.getMessageProducer(null, null);
TextXMLMessage message = producer.createTextXMLMessage();
message.setText("<xml>hello!</xml>");
Destination destination = JCSMPFactory.onlyInstance().createTopicDestination("topic1");
producer.send(message, destination);
} catch (...) {
// exception handling goes here
....
} finally {
// make sure to release all resources
if (producer != null) producer.close();
if (session != null) session.closeSession();
}
The following code displays how to send messages in non-blocking mode.
JCSMPDestinationSession session = null;
DestinationProducer producer = null;
try {
JCSMPProperties props = new JCSMPProperties();
... // setup properties
session = JCSMPFactory.onlyInstance().createDestinationSession(props);
producer = session.getMessageProducer(new MyStreamingCallbackHandler(), null);
TextXMLMessage message = producer.createTextXMLMessage();
message.setText("<xml>hello!</xml>");
Destination destination = JCSMPFactory.onlyInstance().createTopicDestination("topic1");
producer.send(message, destination);
} catch (...) {
// exception handling goes here
....
} finally {
// make sure to release all resources
if (producer != null) producer.close();
if (session != null) session.closeSession();
}
...
// implementation of JCSMPStreamingPublishEventHandler
class MyStreamingCallbackHandler implements JCSMPStreamingPublishEventHandler {
public void handleError(String messageID, JCSMPException cause, long timestamp) {
// handle errors
...
}
public void responseReceived(String messageID) {
// handle response
...
}
}
| Modifier and Type | Method and Description |
|---|---|
void |
send(XMLMessage message)
Sends to the default destination
|
void |
send(XMLMessage message,
Destination destination)
Sends a message to a specific destination.
|
close, createBytesMessage, createBytesXMLMessage, createBytesXMLMessage, createMap, createMapMessage, createStream, createStreamMessage, createStreamXMLMessage, createStreamXMLMessage, createTextMessage, createTextXMLMessage, createTextXMLMessage, createXMLContentMessage, getStreamingCallbackHandlervoid send(XMLMessage message, Destination destination) throws JCSMPException
A new message ID is assigned to the message automatically every time this method is called. The message also becomes read-only, and it cannot be modified by the client application.
message - The message to be sent.destination - The destination to send to.JCSMPException - upon failure.InvalidOperationException - when called on a closed producer.void send(XMLMessage message) throws JCSMPException
message - The message to be sent.JCSMPException - upon failure.InvalidOperationException - when called on a closed producer.Copyright 2004-2019 Solace Corporation. All rights reserved.