Class JDBCMessageStore
- java.lang.Object
-
- org.apache.synapse.message.store.AbstractMessageStore
-
- org.apache.synapse.message.store.impl.jdbc.JDBCMessageStore
-
- All Implemented Interfaces:
ManagedLifecycle
,MessageStore
,Nameable
,SynapseArtifact
- Direct Known Subclasses:
ResequenceMessageStore
public class JDBCMessageStore extends AbstractMessageStore
JDBC Store class
-
-
Field Summary
Fields Modifier and Type Field Description protected static String
MESSAGE_COLUMN_NAME
-
Fields inherited from class org.apache.synapse.message.store.AbstractMessageStore
description, fileName, lock, messageStoreMBean, messageStoreObservers, name, parameterKeyMap, parameters, sequence, synapseConfiguration, synapseEnvironment
-
-
Constructor Summary
Constructors Constructor Description JDBCMessageStore()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Delete all entries from tableprotected MessageContext
deserializeMessage(byte[] msgObj)
Will convert the byte[] message to store-able message.void
destroy()
Destroy Resources allocatedMessageContext
get(int position)
Get the message at given position Only can be done with MYSQL, and no use-case in current implementationMessageContext
get(String msgId)
Return the first element with given msg_idList<MessageContext>
getAll()
Get all messages in the tableMessageConsumer
getConsumer()
Returns a Message Consumer for this message store.protected JDBCConfiguration
getJdbcConfiguration()
protected List<Map>
getProcessedRows(Statement statement)
Will return the list of processed message rows.MessageProducer
getProducer()
Returns a Message Producer for this message store.protected Statement
getStoreMessageStatement(MessageContext messageContext, Long sequenceId)
Generates the statement to store message in database.void
init(SynapseEnvironment synapseEnvironment)
Initializes the JDBC Message Storeprotected List<Map>
messageContentResultSet(ResultSet resultSet, String statement)
Return the messages corresponding to the provided statement.MessageContext
peek()
Select and return the first element in current tableMessageContext
remove()
Removes the first element from tableMessageContext
remove(String msgId)
Remove the message with given msg_idprotected List<Statement>
removeMessageStatement(String msgId)
Statement to remove the message once a response is received.byte[]
serialize(Object obj)
void
setParameters(Map<String,Object> parameters)
Set JDBC store parametersint
size()
Return number of messages in the storeboolean
store(MessageContext messageContext)
Add a message to the end of the table.-
Methods inherited from class org.apache.synapse.message.store.AbstractMessageStore
addParameter, addParameterKey, dequeued, difference, enqueued, getArtifactContainerName, getDescription, getFileName, getLock, getName, getParameterKey, getParameterKeyMap, getParameters, getType, isEdited, nextConsumerId, nextProducerId, notifyMessageAddition, notifyMessageRemoval, registerObserver, setArtifactContainerName, setDescription, setFileName, setIsEdited, setName, unregisterObserver
-
-
-
-
Field Detail
-
MESSAGE_COLUMN_NAME
protected static final String MESSAGE_COLUMN_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
init
public void init(SynapseEnvironment synapseEnvironment)
Initializes the JDBC Message Store- Specified by:
init
in interfaceManagedLifecycle
- Overrides:
init
in classAbstractMessageStore
- Parameters:
synapseEnvironment
- SynapseEnvironment for the store
-
getJdbcConfiguration
protected JDBCConfiguration getJdbcConfiguration()
-
getProducer
public MessageProducer getProducer()
Description copied from interface:MessageStore
Returns a Message Producer for this message store.- Returns:
- A non-null message producer that can produce messages to this message store.
- See Also:
MessageStore.getProducer()
-
getConsumer
public MessageConsumer getConsumer()
Description copied from interface:MessageStore
Returns a Message Consumer for this message store.- Returns:
- A non-null message consumer that can read messages from this message store.
- See Also:
MessageStore.getConsumer()
-
setParameters
public void setParameters(Map<String,Object> parameters)
Set JDBC store parameters- Specified by:
setParameters
in interfaceMessageStore
- Overrides:
setParameters
in classAbstractMessageStore
- Parameters:
parameters
- - List of parameters to set
-
getProcessedRows
protected List<Map> getProcessedRows(Statement statement)
Will return the list of processed message rows.- Parameters:
statement
- the statement executed in the DB.- Returns:
- the rows which contains the column data wrapped inside a map.
-
deserializeMessage
protected MessageContext deserializeMessage(byte[] msgObj)
Will convert the byte[] message to store-able message.- Parameters:
msgObj
- serialized message read from the database.- Returns:
- converted message context.
-
serialize
public byte[] serialize(Object obj) throws IOException
- Throws:
IOException
-
destroy
public void destroy()
Destroy Resources allocated- Specified by:
destroy
in interfaceManagedLifecycle
- Overrides:
destroy
in classAbstractMessageStore
-
store
public boolean store(MessageContext messageContext) throws SynapseException
Add a message to the end of the table. If fetching success return true else false- Parameters:
messageContext
- message to insert- Returns:
- - success/failure of fetching
- Throws:
SynapseException
-
getStoreMessageStatement
protected Statement getStoreMessageStatement(MessageContext messageContext, Long sequenceId) throws StoreException
Generates the statement to store message in database.
If the sequence id is specified the corresponding sequence id will be stored, sequence id will be specified if re-sequence message store is being used. In other times this value will be null.
- Parameters:
messageContext
- the content of the message.sequenceId
- the sequence id of the message (optional).- Returns:
- SQL statement for insertion of value to store.
- Throws:
StoreException
- at an event there's an exception when generating the statement.- See Also:
ResequenceMessageStore
-
peek
public MessageContext peek() throws SynapseException
Select and return the first element in current table- Returns:
- - Select and return the first element from the table
- Throws:
SynapseException
-
remove
public MessageContext remove() throws NoSuchElementException
Removes the first element from table- Returns:
- MessageContext - first message context
- Throws:
NoSuchElementException
- if there was not element to be removed.
-
remove
public MessageContext remove(String msgId) throws SynapseException
Remove the message with given msg_id- Parameters:
msgId
- - message ID- Returns:
- - removed message context
- Throws:
SynapseException
-
removeMessageStatement
protected List<Statement> removeMessageStatement(String msgId)
Statement to remove the message once a response is received.- Parameters:
msgId
- message id of the statement which should be removed.- Returns:
- the sql remove message statement.
-
clear
public void clear()
Delete all entries from table
-
get
public MessageContext get(int position)
Get the message at given position Only can be done with MYSQL, and no use-case in current implementation- Parameters:
position
- - position of the message , starting value is 0- Returns:
- Message Context of position th row or if failed return null
-
getAll
public List<MessageContext> getAll()
Get all messages in the table- Returns:
- - List containing all message contexts in the store
-
get
public MessageContext get(String msgId)
Return the first element with given msg_id- Parameters:
msgId
- - Message ID- Returns:
- - returns the first result found else null
-
messageContentResultSet
protected List<Map> messageContentResultSet(ResultSet resultSet, String statement) throws SQLException
Return the messages corresponding to the provided statement.
- Parameters:
resultSet
- the result-set obtained from the statement.statement
- the SQL statement results are obtained for.- Returns:
- the content of the messages.
- Throws:
SQLException
- during an error encountered when accessing the database.
-
size
public int size()
Return number of messages in the store- Specified by:
size
in interfaceMessageStore
- Overrides:
size
in classAbstractMessageStore
- Returns:
- size - Number of messages
-
-