public interface Producer extends MessageFactory, ServiceLifecycle, Client
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. |
TransactionalResult |
prepare(Message message)
Sends a transactional message to the specified destination synchronously, the destination should be preset to
Message.header() , other header fields as well. |
void |
removeInterceptor(ProducerInterceptor interceptor)
Remove a
ProducerInterceptor . |
void |
send(List<Message> messages)
Send batch messages to server.
|
SendResult |
send(Message message)
Sends a message to the specified destination synchronously, the destination should be preset to
Message.header() , other header fields as well. |
Future<SendResult> |
sendAsync(List<Message> messages)
Send messages to the specified destination asynchronously, the destination should be preset to
Message.header() , 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.header() , other header fields as well. |
void |
sendOneway(List<Message> messages)
There is no
Promise related or RuntimeException thrown. |
void |
sendOneway(Message message)
There is no
Promise related or RuntimeException thrown. |
createMessage
currentState, start, stop
getQueueMetaData
getExtension
SendResult send(Message message)
Message.header()
, other header fields as well.message
- a message will be sent.SendResult
.OMSSecurityException
- when have no authority to send messages to a given destination.OMSMessageFormatException
- when an invalid message is specified.OMSTimeOutException
- when the given timeout elapses before the send operation completes.OMSDestinationException
- when have no given destination in the server.OMSRuntimeException
- when the Producer
fails to send the message due to some internal error.Future<SendResult> sendAsync(Message message)
Message.header()
, 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 sent.Promise
of an asynchronous message send operation.Future
,
FutureListener
void sendOneway(Message message)
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 sent.void send(List<Message> messages)
Send batch messages to server.
messages
- messages to be sent.Future<SendResult> sendAsync(List<Message> messages)
Message.header()
, 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.
messages
- a batch messages will be sent.Promise
of an asynchronous messages send operation.Future
,
FutureListener
void sendOneway(List<Message> messages)
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.
messages
- a batch message will be sent.void addInterceptor(ProducerInterceptor interceptor)
ProducerInterceptor
to intercept send operations of producer.interceptor
- a producer interceptor.void removeInterceptor(ProducerInterceptor interceptor)
ProducerInterceptor
.interceptor
- a producer interceptor will be removed.TransactionalResult prepare(Message message)
Message.header()
, other header fields as well.
A transactional send result will be exposed to consumer if this prepare message send success, and then, you can
execute your local transaction, when local transaction execute success, users can use TransactionalResult.commit()
to commit prepare message,otherwise can use TransactionalResult.rollback()
to roll back this prepare message.
message
- a prepare transactional message will be sent.SendResult
.OMSSecurityException
- when have no authority to send messages to a given destination.OMSMessageFormatException
- when an invalid message is specified.OMSTimeOutException
- when the given timeout elapses before the send operation completes.OMSDestinationException
- when have no given destination in the server.OMSRuntimeException
- when the Producer
fails to send the message due to some internal error.OMSTransactionException
- when used normal producer which haven't register TransactionStateCheckListener
.Copyright © 2017–2020 OpenMessaging. All rights reserved.