Search in sources :

Example 31 with QueueSender

use of javax.jms.QueueSender in project iaf by ibissource.

the class IfsaRequesterSender method sendMessage.

/**
 * Execute a request to the IFSA service.
 * @return in Request/Reply, the retrieved message or TIMEOUT, otherwise null
 */
public String sendMessage(String dummyCorrelationId, String message, Map params, String bifName, byte[] btcData) throws SenderException, TimeOutException {
    String result = null;
    QueueSession session = null;
    QueueSender sender = null;
    Map udzMap = null;
    try {
        log.debug(getLogPrefix() + "creating session and sender");
        session = createSession();
        IFSAQueue queue;
        if (params != null && params.size() > 0) {
            // Use first param as serviceId
            String serviceId = (String) params.get("serviceId");
            if (serviceId == null) {
                serviceId = getServiceId();
            }
            String occurrence = (String) params.get("occurrence");
            if (occurrence != null) {
                int i = serviceId.indexOf('/', serviceId.indexOf('/', serviceId.indexOf('/', serviceId.indexOf('/') + 1) + 1) + 1);
                int j = serviceId.indexOf('/', i + 1);
                serviceId = serviceId.substring(0, i + 1) + occurrence + serviceId.substring(j);
            }
            queue = getMessagingSource().lookupService(getMessagingSource().polishServiceId(serviceId));
            if (queue == null) {
                throw new SenderException(getLogPrefix() + "got null as queue for serviceId [" + serviceId + "]");
            }
            if (log.isDebugEnabled()) {
                log.info(getLogPrefix() + "got Queue to send messages on [" + queue.getQueueName() + "]");
            }
            // Use remaining params as outgoing UDZs
            udzMap = new HashMap();
            udzMap.putAll(params);
            udzMap.remove("serviceId");
            udzMap.remove("occurrence");
        } else {
            queue = getServiceQueue();
        }
        sender = createSender(session, queue);
        log.debug(getLogPrefix() + "sending message with bifName [" + bifName + "]");
        TextMessage sentMessage = sendMessage(session, sender, message, udzMap, bifName, btcData);
        log.debug(getLogPrefix() + "message sent");
        if (isSynchronous()) {
            log.debug(getLogPrefix() + "waiting for reply");
            Message msg = getRawReplyMessage(session, queue, sentMessage);
            try {
                long tsReplyReceived = System.currentTimeMillis();
                long tsRequestSent = sentMessage.getJMSTimestamp();
                long tsReplySent = msg.getJMSTimestamp();
                // }
                if (log.isInfoEnabled()) {
                    log.info(getLogPrefix() + "A) RequestSent   [" + DateUtils.format(tsRequestSent) + "]");
                    log.info(getLogPrefix() + "B) ReplySent     [" + DateUtils.format(tsReplySent) + "] diff (~queing + processing) [" + (tsReplySent - tsRequestSent) + "]");
                    log.info(getLogPrefix() + "C) ReplyReceived [" + DateUtils.format(tsReplyReceived) + "] diff (transport of reply )[" + (tsReplyReceived - tsReplySent) + "]");
                // log.info(getLogPrefix()+"C2) msgRcvd.businessProcStartRcvd  ["+DateUtils.format(businessProcStartRcvd) +"] ");
                // log.info(getLogPrefix()+"D)  msgRcvd.jmsTimestamp           ["+DateUtils.format(jmsTimestampRcvd)      +"] diff ["+(jmsTimestampRcvd-businessProcStartSent)+"]");
                // log.info(getLogPrefix()+"E)  msgRcvd.businessProcFinishRcvd ["+DateUtils.format(businessProcFinishRcvd)+"] diff ["+(businessProcFinishRcvd-jmsTimestampRcvd)+"] (=time spend on IFSA bus sending result?)");
                // log.info(getLogPrefix()+"F)  timestampAfterRcvd             ["+DateUtils.format(timestampAfterRcvd)    +"] diff ["+(timestampAfterRcvd-businessProcFinishRcvd)+"] ");
                // log.info(getLogPrefix()+"business processing time (E-C1) ["+(businessProcFinishRcvd-businessProcStartSent)+"] ");
                }
            // if (businessProcessTimes!=null) {
            // businessProcessTimes.addValue(businessProcFinishRcvd-businessProcStartSent);
            // }
            } catch (JMSException e) {
                log.warn(getLogPrefix() + "exception determining processing times", e);
            }
            if (msg instanceof TextMessage) {
                result = ((TextMessage) msg).getText();
            } else {
                if (msg.getClass().getName().endsWith("IFSAReportMessage")) {
                    if (msg instanceof IFSAReportMessage) {
                        IFSAReportMessage irm = (IFSAReportMessage) msg;
                        if (isThrowExceptions()) {
                            throw new SenderException(getLogPrefix() + "received IFSAReportMessage [" + ToStringBuilder.reflectionToString(irm) + "], NoReplyReason [" + irm.getNoReplyReason() + "]");
                        }
                        log.warn(getLogPrefix() + "received IFSAReportMessage [" + ToStringBuilder.reflectionToString(irm) + "], NoReplyReason [" + irm.getNoReplyReason() + "]");
                        result = "<IFSAReport>" + "<NoReplyReason>" + irm.getNoReplyReason() + "</NoReplyReason>" + "</IFSAReport>";
                    }
                } else {
                    log.warn(getLogPrefix() + "received neither TextMessage nor IFSAReportMessage but [" + msg.getClass().getName() + "]");
                    result = msg.toString();
                }
            }
            if (result == null) {
                log.info(getLogPrefix() + "received null reply");
            } else {
                if (log.isDebugEnabled()) {
                    if (AppConstants.getInstance().getBoolean("log.logIntermediaryResults", false)) {
                        log.debug(getLogPrefix() + "received reply [" + result + "]");
                    } else {
                        log.debug(getLogPrefix() + "received reply");
                    }
                } else {
                    log.info(getLogPrefix() + "received reply");
                }
            }
        } else {
            result = sentMessage.getJMSMessageID();
        }
    } catch (JMSException e) {
        throw new SenderException(getLogPrefix() + "caught JMSException in sendMessage()", e);
    } catch (IfsaException e) {
        throw new SenderException(getLogPrefix() + "caught IfsaException in sendMessage()", e);
    } finally {
        if (sender != null) {
            try {
                log.debug(getLogPrefix() + "closing sender");
                sender.close();
            } catch (JMSException e) {
                log.debug(getLogPrefix() + "Exception closing sender", e);
            }
        }
        closeSession(session);
    }
    if (isThrowExceptions() && result != null && result.startsWith("<exception>")) {
        throw new SenderException("Retrieved exception message from IFSA bus: " + result);
    }
    return result;
}
Also used : IFSAReportMessage(com.ing.ifsa.IFSAReportMessage) IFSATimeOutMessage(com.ing.ifsa.IFSATimeOutMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) HashMap(java.util.HashMap) IFSAReportMessage(com.ing.ifsa.IFSAReportMessage) JMSException(javax.jms.JMSException) IfsaException(nl.nn.adapterframework.extensions.ifsa.IfsaException) IFSAQueue(com.ing.ifsa.IFSAQueue) QueueSender(javax.jms.QueueSender) SenderException(nl.nn.adapterframework.core.SenderException) HashMap(java.util.HashMap) Map(java.util.Map) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage)

Example 32 with QueueSender

use of javax.jms.QueueSender in project iaf by ibissource.

the class JMSFacade method sendByQueue.

protected String sendByQueue(QueueSession session, Queue destination, javax.jms.Message message) throws NamingException, JMSException {
    QueueSender tqs = session.createSender(destination);
    tqs.send(message);
    tqs.close();
    return message.getJMSMessageID();
}
Also used : QueueSender(javax.jms.QueueSender)

Example 33 with QueueSender

use of javax.jms.QueueSender in project qpid-broker-j by apache.

the class QueueSenderTest method sendToUnknownQueue.

@Test
public void sendToUnknownQueue() throws Exception {
    QueueConnection connection = ((QueueConnection) getConnectionBuilder().build());
    try {
        QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue invalidDestination = session.createQueue("unknown");
        try {
            QueueSender sender = session.createSender(invalidDestination);
            sender.send(session.createMessage());
            fail("Exception not thrown");
        } catch (InvalidDestinationException e) {
        // PASS
        }
    } finally {
        connection.close();
    }
}
Also used : QueueConnection(javax.jms.QueueConnection) QueueSender(javax.jms.QueueSender) InvalidDestinationException(javax.jms.InvalidDestinationException) Queue(javax.jms.Queue) QueueSession(javax.jms.QueueSession) Test(org.junit.Test)

Example 34 with QueueSender

use of javax.jms.QueueSender in project qpid-broker-j by apache.

the class QueueSenderTest method anonymousSenderSendToUnknownQueue.

@Test
public void anonymousSenderSendToUnknownQueue() throws Exception {
    QueueConnection connection = ((QueueConnection) getConnectionBuilder().setSyncPublish(true).build());
    try {
        QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue invalidDestination = session.createQueue("unknown");
        try {
            QueueSender sender = session.createSender(null);
            sender.send(invalidDestination, session.createMessage());
            fail("Exception not thrown");
        } catch (InvalidDestinationException e) {
        // PASS
        }
    } finally {
        connection.close();
    }
}
Also used : QueueConnection(javax.jms.QueueConnection) QueueSender(javax.jms.QueueSender) InvalidDestinationException(javax.jms.InvalidDestinationException) Queue(javax.jms.Queue) QueueSession(javax.jms.QueueSession) Test(org.junit.Test)

Example 35 with QueueSender

use of javax.jms.QueueSender in project wildfly by wildfly.

the class QueueTestMDB method sendReply.

private void sendReply(Queue destination, String messageID) throws JMSException {
    QueueConnection conn = qFactory.createQueueConnection();
    try {
        QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
        QueueSender sender = session.createSender(destination);
        TextMessage message = session.createTextMessage("SUCCESS");
        message.setJMSCorrelationID(messageID);
        sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 500);
    } finally {
        conn.close();
    }
}
Also used : QueueConnection(javax.jms.QueueConnection) QueueSender(javax.jms.QueueSender) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage)

Aggregations

QueueSender (javax.jms.QueueSender)59 QueueSession (javax.jms.QueueSession)54 Queue (javax.jms.Queue)36 TextMessage (javax.jms.TextMessage)28 QueueReceiver (javax.jms.QueueReceiver)25 JMSException (javax.jms.JMSException)14 Message (javax.jms.Message)14 QueueConnection (javax.jms.QueueConnection)14 Test (org.junit.jupiter.api.Test)14 Serializable (java.io.Serializable)11 ObjectMessage (javax.jms.ObjectMessage)10 Test (org.junit.Test)8 RMQDestination (com.rabbitmq.jms.admin.RMQDestination)5 InitialContext (javax.naming.InitialContext)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 MapMessage (javax.jms.MapMessage)4 QueueConnectionFactory (javax.jms.QueueConnectionFactory)4 IFSAQueue (com.ing.ifsa.IFSAQueue)3 GetResponse (com.rabbitmq.client.GetResponse)3