use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class JmsConsumer method receive.
public MessageContext receive() {
boolean connectionSuccess = checkAndTryConnect();
if (!connectionSuccess) {
throw new SynapseException(idString + "Error while connecting to JMS provider. " + MessageProcessorConstants.STORE_CONNECTION_ERROR);
}
try {
Message message = consumer.receive(1);
if (message == null) {
return null;
}
if (!(message instanceof ObjectMessage)) {
logger.warn("JMS Consumer " + getId() + " did not receive a javax.jms.ObjectMessage");
// we just discard this message as we only store Object messages via JMS Message store
message.acknowledge();
return null;
}
ObjectMessage msg = (ObjectMessage) message;
String messageId = msg.getStringProperty(Constants.OriginalMessageID);
if (!(msg.getObject() instanceof StorableMessage)) {
logger.warn("JMS Consumer " + getId() + " did not receive a valid message.");
message.acknowledge();
return null;
}
// create a ,essage context back from the stored message
StorableMessage storableMessage = (StorableMessage) msg.getObject();
org.apache.axis2.context.MessageContext axis2Mc = store.newAxis2Mc();
MessageContext synapseMc = store.newSynapseMc(axis2Mc);
synapseMc = MessageConverter.toMessageContext(storableMessage, axis2Mc, synapseMc);
// cache the message
updateCache(message, synapseMc, messageId, false);
if (logger.isDebugEnabled()) {
logger.debug(getId() + " Received MessageId:" + messageId + " priority:" + message.getJMSPriority());
}
return synapseMc;
} catch (JMSException e) {
logger.error("Cannot fetch messages from Store " + store.getName());
updateCache(null, null, "", true);
cleanup();
/* try connecting and receiving again. Try to connect will happen configured number of times
and give up with a SynapseException */
return receive();
}
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class JDBCMessageStore method remove.
/**
* Remove the message with given msg_id
*
* @param msgId - message ID
* @return - removed message context
*/
@Override
public MessageContext remove(String msgId) throws SynapseException {
MessageContext result;
boolean cleaningState = false;
try {
if (cleaningFlag.get()) {
try {
removeLock.lock();
cleaningState = true;
} catch (Exception ie) {
logger.error("Message Cleanup lock released unexpectedly", ie);
}
}
result = get(msgId);
List<Statement> statements = removeMessageStatement(msgId);
processNonResultingStatement(statements);
} catch (Exception e) {
throw new SynapseException("Removing message with id = " + msgId + " failed !", e);
} finally {
if (cleaningState) {
removeLock.unlock();
}
}
return result;
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class JDBCMessageStore method remove.
/**
* Removes the first element from table
*
* @return MessageContext - first message context
* @throws NoSuchElementException if there was not element to be removed.
*/
@Override
public MessageContext remove() throws NoSuchElementException {
MessageContext messageContext = peek();
messageContext = remove(messageContext.getMessageID());
if (messageContext != null) {
return messageContext;
} else {
throw new NoSuchElementException("First element not found and remove failed !");
}
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class JDBCMessageStore method getResultMessageContextFromDatabase.
/**
* Process a given SQL statement.
*
* @param statement - Statement to process.
* @return - MessageContext which will hold the content of the message.
*/
private MessageContext getResultMessageContextFromDatabase(Statement statement) throws SynapseException {
List<Map> processedRows = getProcessedRows(statement);
final int firstRowIndex = 0;
MessageContext messageContext = null;
if (processedRows.size() > 0) {
Map messageContentRow = processedRows.get(firstRowIndex);
messageContext = (MessageContext) messageContentRow.get(MESSAGE_COLUMN_NAME);
if (logger.isDebugEnabled()) {
logger.debug("Number of rows processed:" + processedRows + " calling the statement " + statement.getStatement());
logger.debug("Message content with mid:" + messageContext.getMessageID() + " will be returned");
}
}
return messageContext;
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class JDBCMessageStore method peek.
/**
* Select and return the first element in current table
*
* @return - Select and return the first element from the table
*/
public MessageContext peek() throws SynapseException {
MessageContext msg;
try {
Statement statement = new Statement("SELECT message FROM " + jdbcConfiguration.getTableName() + " WHERE indexId=(SELECT min(indexId) from " + jdbcConfiguration.getTableName() + ")") {
@Override
public List<Map> getResult(ResultSet resultSet) throws SQLException {
return messageContentResultSet(resultSet, this.getStatement());
}
};
msg = getResultMessageContextFromDatabase(statement);
} catch (SynapseException se) {
throw new SynapseException("Error while peek the message", se);
}
return msg;
}
Aggregations