List of usage examples for javax.jms QueueSession commit
void commit() throws JMSException;
From source file:nl.nn.adapterframework.extensions.ifsa.jms.IfsaFacade.java
/** * Sends a message,and if transacted, the queueSession is committed. * <p>This method is intended for <b>clients</b>, as <b>server</b>s * will use the <code>sendReply</code>. * @return the correlationID of the sent message *///w ww .j a v a 2 s . co m public TextMessage sendMessage(QueueSession session, QueueSender sender, String message, Map udzMap, String bifName, byte btcData[]) throws IfsaException { try { if (!isRequestor()) { throw new IfsaException(getLogPrefix() + "Provider cannot use sendMessage, should use sendReply"); } IFSATextMessage msg = (IFSATextMessage) session.createTextMessage(); msg.setText(message); if (udzMap != null && msg instanceof IFSAMessage) { // Handle UDZs log.debug(getLogPrefix() + "add UDZ map to IFSAMessage"); // process the udzMap Map udzObject = (Map) ((IFSAMessage) msg).getOutgoingUDZObject(); udzObject.putAll(udzMap); } String replyToQueueName = "-"; //Client side if (messageProtocol.equals(IfsaMessageProtocolEnum.REQUEST_REPLY)) { // set reply-to address Queue replyTo = getMessagingSource().getClientReplyQueue(session); msg.setJMSReplyTo(replyTo); replyToQueueName = replyTo.getQueueName(); } if (messageProtocol.equals(IfsaMessageProtocolEnum.FIRE_AND_FORGET)) { // not applicable } if (StringUtils.isNotEmpty(bifName)) { msg.setBifName(bifName); } if (btcData != null && btcData.length > 0) { msg.setBtcData(btcData); } if (log.isDebugEnabled()) { log.debug(getLogPrefix() + " messageProtocol [" + messageProtocol + "] replyToQueueName [" + replyToQueueName + "] sending message [" + message + "]"); } else { if (log.isInfoEnabled()) { log.info(getLogPrefix() + " messageProtocol [" + messageProtocol + "] replyToQueueName [" + replyToQueueName + "] sending message"); } } // send the message sender.send(msg); // perform commit if (isJmsTransacted() && !(messagingSource.isXaEnabledForSure() && JtaUtil.inTransaction())) { session.commit(); log.debug(getLogPrefix() + "committing (send) transaction"); } return msg; } catch (Exception e) { throw new IfsaException(e); } }
From source file:nl.nn.adapterframework.extensions.ifsa.jms.PullingIfsaProviderListener.java
public void afterMessageProcessed(PipeLineResult plr, Object rawMessage, Map threadContext) throws ListenerException { try {/*from w w w. j av a2 s.co m*/ if (isJmsTransacted() && !(getMessagingSource().isXaEnabledForSure() && JtaUtil.inTransaction())) { QueueSession session = (QueueSession) threadContext.get(THREAD_CONTEXT_SESSION_KEY); try { session.commit(); } catch (JMSException e) { log.error(getLogPrefix() + "got error committing the received message", e); } if (isSessionsArePooled()) { threadContext.remove(THREAD_CONTEXT_SESSION_KEY); releaseSession(session); } } } catch (Exception e) { log.error(getLogPrefix() + "exception in closing or releasing session", e); } // on request-reply send the reply. if (getMessageProtocolEnum().equals(IfsaMessageProtocolEnum.REQUEST_REPLY)) { Message originalRawMessage; if (rawMessage instanceof Message) { originalRawMessage = (Message) rawMessage; } else { originalRawMessage = (Message) threadContext.get(THREAD_CONTEXT_ORIGINAL_RAW_MESSAGE_KEY); } if (originalRawMessage == null) { String id = (String) threadContext.get(IPipeLineSession.messageIdKey); String cid = (String) threadContext.get(IPipeLineSession.businessCorrelationIdKey); log.warn(getLogPrefix() + "no original raw message found for messageId [" + id + "] correlationId [" + cid + "], cannot send result"); } else { QueueSession session = getSession(threadContext); try { String result = "<exception>no result</exception>"; if (plr != null && plr.getResult() != null) { result = plr.getResult(); } sendReply(session, originalRawMessage, result); } catch (IfsaException e) { try { sendReply(session, originalRawMessage, "<exception>" + e.getMessage() + "</exception>"); } catch (IfsaException e2) { log.warn(getLogPrefix() + "exception sending errormessage as reply", e2); } throw new ListenerException(getLogPrefix() + "Exception on sending result", e); } finally { releaseSession(session); } } } }