Class MessageQueue
java.lang.Object
org.pipservices3.messaging.queues.MessageQueue
- All Implemented Interfaces:
org.pipservices3.commons.config.IConfigurable,org.pipservices3.commons.refer.IReferenceable,org.pipservices3.commons.run.IClosable,org.pipservices3.commons.run.IOpenable,IMessageQueue
- Direct Known Subclasses:
MemoryMessageQueue
public abstract class MessageQueue extends Object implements IMessageQueue, org.pipservices3.commons.refer.IReferenceable, org.pipservices3.commons.config.IConfigurable, org.pipservices3.commons.run.IOpenable, org.pipservices3.commons.run.IClosable
Abstract message queue that is used as a basis for specific message queue implementations.
### Configuration parameters ###
- name: name of the message queue
- connection(s):
- discovery_key: key to retrieve parameters from discovery service
- protocol: connection protocol like http, https, tcp, udp
- host: host name or IP address
- port: port number
- uri: resource URI or connection string with all parameters in it
- credential(s):
- store_key: key to retrieve parameters from credential store
- username: user name
- password: user password
- access_id: application access id
- access_key: application secret key
### References ###
- *:logger:*:*:1.0 (optional) ILogger components to pass log messages
- *:counters:*:*:1.0 (optional) ICounters components to pass collected measurements
- *:discovery:*:*:1.0 (optional) IDiscovery services to resolve connection
- *:credential-store:*:*:1.0 (optional) ICredentialStore componetns to lookup credential(s)
-
Field Summary
Fields Modifier and Type Field Description protected MessagingCapabilities_capabilitiesprotected org.pipservices3.components.connect.ConnectionResolver_connectionResolverprotected org.pipservices3.components.count.CompositeCounters_countersprotected org.pipservices3.components.auth.CredentialResolver_credentialResolverprotected String_kindprotected Object_lockprotected org.pipservices3.components.log.CompositeLogger_loggerprotected String_name -
Constructor Summary
Constructors Constructor Description MessageQueue()Creates a new instance of the message queue.MessageQueue(String name)Creates a new instance of the message queue.MessageQueue(String name, org.pipservices3.commons.config.ConfigParams config)Creates a new instance of the message queue. -
Method Summary
Modifier and Type Method Description abstract voidabandon(MessageEnvelop message)Returnes message into the queue and makes it available for all subscribers to receive it again.voidbeginListen(String correlationId, IMessageReceiver receiver)Listens for incoming messages without blocking the current thread.abstract voidclear(String correlationId)Clears component state.abstract voidclose(String correlationId)Closes component and frees used resources.abstract voidcomplete(MessageEnvelop message)Permanently removes a message from the queue.voidconfigure(org.pipservices3.commons.config.ConfigParams config)Configures component by passing configuration parameters.abstract voidendListen(String correlationId)Ends listening for incoming messages.MessagingCapabilitiesgetCapabilities()Gets the queue capabilitiesabstract LonggetMessageCount()Gets the current number of messages in the queue to be delivered.StringgetName()Gets the queue nameabstract booleanisOpen()Checks if the component is opened.abstract voidlisten(String correlationId, IMessageReceiver receiver)Listens for incoming messages and blocks the current thread until queue is closed.abstract voidmoveToDeadLetter(MessageEnvelop message)Permanently removes a message from the queue and sends it to dead letter queue.voidopen(String correlationId)Opens the component.abstract voidopen(String correlationId, org.pipservices3.components.connect.ConnectionParams connection, org.pipservices3.components.auth.CredentialParams credential)Opens the component with given connection and credential parameters.abstract MessageEnveloppeek(String correlationId)Peeks a single incoming message from the queue without removing it.abstract List<MessageEnvelop>peekBatch(String correlationId, int messageCount)Peeks multiple incoming messages from the queue without removing them.abstract MessageEnvelopreceive(String correlationId, long waitTimeout)Receives an incoming message and removes it from the queue.abstract voidrenewLock(MessageEnvelop message, long lockTimeout)Renews a lock on a message that makes it invisible from other receivers in the queue.abstract voidsend(String correlationId, MessageEnvelop message)Sends a message into the queue.voidsendAsObject(String correlationId, String messageType, Object message)Sends an object into the queue.voidsetReferences(org.pipservices3.commons.refer.IReferences references)Sets references to dependent components.StringtoString()Gets a string representation of the object.
-
Field Details
-
_name
-
_kind
-
_capabilities
-
_lock
-
_logger
protected org.pipservices3.components.log.CompositeLogger _logger -
_counters
protected org.pipservices3.components.count.CompositeCounters _counters -
_connectionResolver
protected org.pipservices3.components.connect.ConnectionResolver _connectionResolver -
_credentialResolver
protected org.pipservices3.components.auth.CredentialResolver _credentialResolver
-
-
Constructor Details
-
MessageQueue
public MessageQueue()Creates a new instance of the message queue. -
MessageQueue
Creates a new instance of the message queue.- Parameters:
name- (optional) a queue name
-
MessageQueue
Creates a new instance of the message queue.- Parameters:
name- (optional) a queue nameconfig- configuration parameters
-
-
Method Details
-
configure
public void configure(org.pipservices3.commons.config.ConfigParams config)Configures component by passing configuration parameters.- Specified by:
configurein interfaceorg.pipservices3.commons.config.IConfigurable- Parameters:
config- configuration parameters to be set.
-
setReferences
public void setReferences(org.pipservices3.commons.refer.IReferences references) throws org.pipservices3.commons.refer.ReferenceExceptionSets references to dependent components.- Specified by:
setReferencesin interfaceorg.pipservices3.commons.refer.IReferenceable- Parameters:
references- references to locate the component dependencies.- Throws:
org.pipservices3.commons.refer.ReferenceException- when no found references.
-
getName
Gets the queue name- Specified by:
getNamein interfaceIMessageQueue- Returns:
- the queue name.
-
getCapabilities
Gets the queue capabilities- Specified by:
getCapabilitiesin interfaceIMessageQueue- Returns:
- the queue's capabilities object.
-
getMessageCount
Description copied from interface:IMessageQueueGets the current number of messages in the queue to be delivered.- Specified by:
getMessageCountin interfaceIMessageQueue- Returns:
- number of messages.
-
isOpen
public abstract boolean isOpen()Checks if the component is opened.- Specified by:
isOpenin interfaceorg.pipservices3.commons.run.IOpenable- Returns:
- true if the component has been opened and false otherwise.
-
open
Opens the component.- Specified by:
openin interfaceorg.pipservices3.commons.run.IOpenable- Parameters:
correlationId- (optional) transaction id to trace execution through call chain.- Throws:
org.pipservices3.commons.errors.ApplicationException- when error occured.
-
open
public abstract void open(String correlationId, org.pipservices3.components.connect.ConnectionParams connection, org.pipservices3.components.auth.CredentialParams credential) throws org.pipservices3.commons.errors.ApplicationExceptionOpens the component with given connection and credential parameters.- Parameters:
correlationId- (optional) transaction id to trace execution through call chain.connection- connection parameterscredential- credential parameters- Throws:
org.pipservices3.commons.errors.ApplicationException- when error occured.
-
close
public abstract void close(String correlationId) throws org.pipservices3.commons.errors.ApplicationExceptionCloses component and frees used resources.- Specified by:
closein interfaceorg.pipservices3.commons.run.IClosable- Parameters:
correlationId- (optional) transaction id to trace execution through call chain.- Throws:
org.pipservices3.commons.errors.ApplicationException- when error occured.
-
clear
public abstract void clear(String correlationId) throws org.pipservices3.commons.errors.ApplicationExceptionClears component state.- Parameters:
correlationId- (optional) transaction id to trace execution through call chain.- Throws:
org.pipservices3.commons.errors.ApplicationException- when error occured.
-
send
public abstract void send(String correlationId, MessageEnvelop message) throws org.pipservices3.commons.errors.ApplicationExceptionSends a message into the queue.- Specified by:
sendin interfaceIMessageQueue- Parameters:
correlationId- (optional) transaction id to trace execution through call chain.message- a message envelop to be sent.- Throws:
org.pipservices3.commons.errors.ApplicationException- when error occured.
-
sendAsObject
public void sendAsObject(String correlationId, String messageType, Object message) throws org.pipservices3.commons.errors.ApplicationExceptionSends an object into the queue. Before sending the object is converted into JSON string and wrapped in a [[MessageEnvelop]].- Specified by:
sendAsObjectin interfaceIMessageQueue- Parameters:
correlationId- (optional) transaction id to trace execution through call chain.messageType- a message typemessage- an object value to be sent- Throws:
org.pipservices3.commons.errors.ApplicationException- when error occured.- See Also:
send(String, MessageEnvelop)
-
peek
public abstract MessageEnvelop peek(String correlationId) throws org.pipservices3.commons.errors.ApplicationExceptionPeeks a single incoming message from the queue without removing it. If there are no messages available in the queue it returns null.- Specified by:
peekin interfaceIMessageQueue- Parameters:
correlationId- (optional) transaction id to trace execution through call chain.- Returns:
- a message envelop object.
- Throws:
org.pipservices3.commons.errors.ApplicationException- when error occured.
-
peekBatch
public abstract List<MessageEnvelop> peekBatch(String correlationId, int messageCount) throws org.pipservices3.commons.errors.ApplicationExceptionPeeks multiple incoming messages from the queue without removing them. If there are no messages available in the queue it returns an empty list.- Specified by:
peekBatchin interfaceIMessageQueue- Parameters:
correlationId- (optional) transaction id to trace execution through call chain.messageCount- a maximum number of messages to peek.- Returns:
- a list with messages.
- Throws:
org.pipservices3.commons.errors.ApplicationException- when error occured.
-
receive
public abstract MessageEnvelop receive(String correlationId, long waitTimeout) throws org.pipservices3.commons.errors.ApplicationExceptionReceives an incoming message and removes it from the queue.- Specified by:
receivein interfaceIMessageQueue- Parameters:
correlationId- (optional) transaction id to trace execution through call chain.waitTimeout- a timeout in milliseconds to wait for a message to come.- Returns:
- a message envelop object.
- Throws:
org.pipservices3.commons.errors.ApplicationException- when error occured.
-
renewLock
public abstract void renewLock(MessageEnvelop message, long lockTimeout) throws org.pipservices3.commons.errors.ApplicationExceptionRenews a lock on a message that makes it invisible from other receivers in the queue. This method is usually used to extend the message processing time.- Specified by:
renewLockin interfaceIMessageQueue- Parameters:
message- a message to extend its lock.lockTimeout- a locking timeout in milliseconds.- Throws:
org.pipservices3.commons.errors.ApplicationException- when error occured.
-
abandon
public abstract void abandon(MessageEnvelop message) throws org.pipservices3.commons.errors.ApplicationExceptionReturnes message into the queue and makes it available for all subscribers to receive it again. This method is usually used to return a message which could not be processed at the moment to repeat the attempt. Messages that cause unrecoverable errors shall be removed permanently or/and send to dead letter queue.- Specified by:
abandonin interfaceIMessageQueue- Parameters:
message- a message to return.- Throws:
org.pipservices3.commons.errors.ApplicationException- when error occured.
-
complete
public abstract void complete(MessageEnvelop message) throws org.pipservices3.commons.errors.ApplicationExceptionPermanently removes a message from the queue. This method is usually used to remove the message after successful processing.- Specified by:
completein interfaceIMessageQueue- Parameters:
message- a message to remove.- Throws:
org.pipservices3.commons.errors.ApplicationException- when error occured.
-
moveToDeadLetter
public abstract void moveToDeadLetter(MessageEnvelop message) throws org.pipservices3.commons.errors.ApplicationExceptionPermanently removes a message from the queue and sends it to dead letter queue.- Specified by:
moveToDeadLetterin interfaceIMessageQueue- Parameters:
message- a message to be removed.- Throws:
org.pipservices3.commons.errors.ApplicationException- when error occured.
-
listen
public abstract void listen(String correlationId, IMessageReceiver receiver) throws org.pipservices3.commons.errors.ApplicationExceptionListens for incoming messages and blocks the current thread until queue is closed.- Specified by:
listenin interfaceIMessageQueue- Parameters:
correlationId- (optional) transaction id to trace execution through call chain.receiver- a receiver to receive incoming messages.- Throws:
org.pipservices3.commons.errors.ApplicationException- when error occured.- See Also:
IMessageReceiver
-
beginListen
Listens for incoming messages without blocking the current thread.- Specified by:
beginListenin interfaceIMessageQueue- Parameters:
correlationId- (optional) transaction id to trace execution through call chain.receiver- a receiver to receive incoming messages.- See Also:
IMessageReceiver
-
endListen
public abstract void endListen(String correlationId) throws org.pipservices3.commons.errors.ApplicationExceptionEnds listening for incoming messages. When this method is call [[listen]] unblocks the thread and execution continues.- Specified by:
endListenin interfaceIMessageQueue- Parameters:
correlationId- (optional) transaction id to trace execution through call chain.- Throws:
org.pipservices3.commons.errors.ApplicationException- when error occured.
-
toString
Gets a string representation of the object.
-