Search in sources :

Example 1 with JmsEnvelopeSenderException

use of uk.gov.justice.services.messaging.jms.exception.JmsEnvelopeSenderException in project microservice_framework by CJSCommonPlatform.

the class DefaultJmsEnvelopeSender method send.

/**
 * Sends envelope to the destination via JMS.
 *
 * @param envelope    envelope to be sent.
 * @param destination JMS destination for the envelope.
 */
@Override
public void send(final JsonEnvelope envelope, final Destination destination) {
    traceLogger.trace(LOGGER, () -> format("Sending JMS message: %s to %s", envelope, destination.toString()));
    try (Connection connection = connectionFactory.createConnection();
        Session session = connection.createSession(false, AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer(destination)) {
        producer.send(envelopeConverter.toMessage(envelope, session));
    } catch (JMSException e) {
        throw new JmsEnvelopeSenderException(format("Exception while sending envelope with name %s", envelope.metadata().name()), e);
    }
    traceLogger.trace(LOGGER, () -> format("Sent JMS message: %s to %s", envelope, destination.toString()));
}
Also used : JmsEnvelopeSenderException(uk.gov.justice.services.messaging.jms.exception.JmsEnvelopeSenderException) Connection(javax.jms.Connection) JMSException(javax.jms.JMSException) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session)

Example 2 with JmsEnvelopeSenderException

use of uk.gov.justice.services.messaging.jms.exception.JmsEnvelopeSenderException in project microservice_framework by CJSCommonPlatform.

the class DefaultJmsEnvelopeSender method send.

/**
 * Sends envelope to the destination via JMS.
 *
 * @param envelope        envelope to be sent.
 * @param destinationName JNDI name of the JMS destination.
 */
@Override
public void send(final JsonEnvelope envelope, final String destinationName) {
    try {
        final Destination destination = (Destination) namingContext.lookup(destinationName);
        send(envelope, destination);
    } catch (NamingException e) {
        throw new JmsEnvelopeSenderException(format("Exception while looking up JMS destination name %s", destinationName), e);
    }
}
Also used : Destination(javax.jms.Destination) JmsEnvelopeSenderException(uk.gov.justice.services.messaging.jms.exception.JmsEnvelopeSenderException) NamingException(javax.naming.NamingException)

Aggregations

JmsEnvelopeSenderException (uk.gov.justice.services.messaging.jms.exception.JmsEnvelopeSenderException)2 Connection (javax.jms.Connection)1 Destination (javax.jms.Destination)1 JMSException (javax.jms.JMSException)1 MessageProducer (javax.jms.MessageProducer)1 Session (javax.jms.Session)1 NamingException (javax.naming.NamingException)1