public interface Producer extends MessageFactory, ServiceLifecycle
Producer is a simple object used to send messages on behalf
of a MessagingAccessPoint. An instance of Producer is
created by calling the MessagingAccessPoint.createProducer() method.
It provides various send methods to send a message to a specified destination,
which is a Queue in OMS.
send(Message) means send a message to the destination synchronously,
the calling thread will block until the send request complete.
sendAsync(Message) means send a message to the destination asynchronously,
the calling thread won't block and will return immediately. Since the send call is asynchronous
it returns a Future for the send result.
| Modifier and Type | Method and Description |
|---|---|
void |
addInterceptor(ProducerInterceptor interceptor)
Adds a
ProducerInterceptor to intercept send operations of producer. |
KeyValue |
attributes()
Returns the attributes of this
Producer instance. |
BatchMessageSender |
createBatchMessageSender()
Creates a
BatchMessageSender to send message in batch manner. |
void |
removeInterceptor(ProducerInterceptor interceptor)
Removes a
ProducerInterceptor |
SendResult |
send(Message message)
Sends a message to the specified destination synchronously, the destination should be preset to
Message.sysHeaders(), other header fields as well. |
SendResult |
send(Message message,
KeyValue attributes)
Sends a message to the specified destination synchronously, using the specified attributes, the destination
should be preset to
Message.sysHeaders(), other header fields as well. |
SendResult |
send(Message message,
LocalTransactionExecutor branchExecutor,
KeyValue attributes)
Sends a transactional message to the specified destination synchronously, using the specified attributes,
the destination should be preset to
Message.sysHeaders(), other header fields as well. |
Future<SendResult> |
sendAsync(Message message)
Sends a message to the specified destination asynchronously, the destination should be preset to
Message.sysHeaders(), other header fields as well. |
Future<SendResult> |
sendAsync(Message message,
KeyValue attributes)
Sends a message to the specified destination asynchronously, using the specified attributes, the destination
should be preset to
Message.sysHeaders(), other header fields as well. |
void |
sendOneway(Message message)
Sends a message to the specified destination in one way, the destination should be preset to
Message.BuiltinKeys, other header fields as well. |
void |
sendOneway(Message message,
KeyValue properties)
Sends a message to the specified destination in one way, using the specified attributes, the destination
should be preset to
Message.BuiltinKeys, other header fields as well. |
createBytesMessageshutdown, startupKeyValue attributes()
Producer instance.
Changes to the return KeyValue are not reflected in physical Producer.
There are some standard attributes defined by OMS for Producer:
OMSBuiltinKeys.PRODUCER_ID, the unique producer id for a producer instance.
OMSBuiltinKeys.OPERATION_TIMEOUT, the default timeout period for operations of Producer.
SendResult send(Message message)
Message.sysHeaders(), other header fields as well.message - a message will be sentSendResultOMSMessageFormatException - if an invalid message is specified.OMSTimeOutException - if the given timeout elapses before the send operation completesOMSRuntimeException - if the Producer fails to send the message due to some internal error.SendResult send(Message message, KeyValue attributes)
Message.sysHeaders(), other header fields as well.message - a message will be sentattributes - the specified attributesSendResultOMSMessageFormatException - if an invalid message is specified.OMSTimeOutException - if the given timeout elapses before the send operation completesOMSRuntimeException - if the Producer fails to send the message due to some internal error.SendResult send(Message message, LocalTransactionExecutor branchExecutor, KeyValue attributes)
Message.sysHeaders(), other header fields as well.
A transactional message will be exposed to consumer if and only if the local transaction branch has been committed, or be discarded if local transaction has been rolled back.
message - a transactional message will be sentbranchExecutor - local transaction executor associated with the messageattributes - the specified attributesSendResultOMSMessageFormatException - if an invalid message is specified.OMSTimeOutException - if the given timeout elapses before the send operation completesOMSRuntimeException - if the Producer fails to send the message due to some internal error.Future<SendResult> sendAsync(Message message)
Message.sysHeaders(), other header fields as well.
The returned Promise will have the result once the operation completes, and the registered
FutureListener will be notified, either because the operation was successful or because of an error.
message - a message will be sentPromise of an asynchronous message send operation.Future,
FutureListenerFuture<SendResult> sendAsync(Message message, KeyValue attributes)
Message.sysHeaders(), other header fields as well.
The returned Promise will have the result once the operation completes, and the registered
FutureListener will be notified, either because the operation was successful or because of an error.
message - a message will be sentattributes - the specified attributesPromise of an asynchronous message send operation.Future,
FutureListenervoid sendOneway(Message message)
Message.BuiltinKeys, other header fields as well.
There is no Promise related or RuntimeException thrown. The calling thread doesn't
care about the send result and also have no context to get the result.
message - a message will be sentvoid sendOneway(Message message, KeyValue properties)
Message.BuiltinKeys, other header fields as well.
There is no Promise related or RuntimeException thrown. The calling thread doesn't
care about the send result and also have no context to get the result.
message - a message will be sentproperties - the specified userHeadersBatchMessageSender createBatchMessageSender()
BatchMessageSender to send message in batch manner.BatchMessageSender instancevoid addInterceptor(ProducerInterceptor interceptor)
ProducerInterceptor to intercept send operations of producer.interceptor - a producer interceptorvoid removeInterceptor(ProducerInterceptor interceptor)
ProducerInterceptorinterceptor - a producer interceptor will be removedCopyright © 2017–2018 OpenMessaging. All rights reserved.