Search in sources :

Example 21 with Destination

use of jakarta.jms.Destination in project spring-framework by spring-projects.

the class DefaultMessageListenerContainerTests method createContainer.

private DefaultMessageListenerContainer createContainer(ConnectionFactory connectionFactory) {
    Destination destination = new Destination() {
    };
    DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
    container.setConnectionFactory(connectionFactory);
    container.setCacheLevel(DefaultMessageListenerContainer.CACHE_NONE);
    container.setDestination(destination);
    return container;
}
Also used : Destination(jakarta.jms.Destination)

Example 22 with Destination

use of jakarta.jms.Destination in project spring-framework by spring-projects.

the class JmsResponseTests method destinationDoesNotUseDestinationResolver.

@Test
public void destinationDoesNotUseDestinationResolver() throws JMSException {
    Destination destination = mock(Destination.class);
    Destination actual = JmsResponse.forDestination("foo", destination).resolveDestination(null, null);
    assertThat(actual).isSameAs(destination);
}
Also used : Destination(jakarta.jms.Destination) Test(org.junit.jupiter.api.Test)

Example 23 with Destination

use of jakarta.jms.Destination in project spring-framework by spring-projects.

the class JndiDestinationResolver method resolveDestinationName.

@Override
public Destination resolveDestinationName(@Nullable Session session, String destinationName, boolean pubSubDomain) throws JMSException {
    Assert.notNull(destinationName, "Destination name must not be null");
    Destination dest = this.destinationCache.get(destinationName);
    if (dest != null) {
        validateDestination(dest, destinationName, pubSubDomain);
    } else {
        try {
            dest = lookup(destinationName, Destination.class);
            validateDestination(dest, destinationName, pubSubDomain);
        } catch (NamingException ex) {
            if (logger.isDebugEnabled()) {
                logger.debug("Destination [" + destinationName + "] not found in JNDI", ex);
            }
            if (this.fallbackToDynamicDestination) {
                dest = this.dynamicDestinationResolver.resolveDestinationName(session, destinationName, pubSubDomain);
            } else {
                throw new DestinationResolutionException("Destination [" + destinationName + "] not found in JNDI", ex);
            }
        }
        if (this.cache) {
            this.destinationCache.put(destinationName, dest);
        }
    }
    return dest;
}
Also used : Destination(jakarta.jms.Destination) NamingException(javax.naming.NamingException)

Example 24 with Destination

use of jakarta.jms.Destination in project spring-framework by spring-projects.

the class SimpleJmsHeaderMapper method fromHeaders.

@Override
public void fromHeaders(MessageHeaders headers, jakarta.jms.Message jmsMessage) {
    try {
        Object jmsCorrelationId = headers.get(JmsHeaders.CORRELATION_ID);
        if (jmsCorrelationId instanceof Number) {
            jmsCorrelationId = jmsCorrelationId.toString();
        }
        if (jmsCorrelationId instanceof String) {
            try {
                jmsMessage.setJMSCorrelationID((String) jmsCorrelationId);
            } catch (Exception ex) {
                logger.debug("Failed to set JMSCorrelationID - skipping", ex);
            }
        }
        Destination jmsReplyTo = getHeaderIfAvailable(headers, JmsHeaders.REPLY_TO, Destination.class);
        if (jmsReplyTo != null) {
            try {
                jmsMessage.setJMSReplyTo(jmsReplyTo);
            } catch (Exception ex) {
                logger.debug("Failed to set JMSReplyTo - skipping", ex);
            }
        }
        String jmsType = getHeaderIfAvailable(headers, JmsHeaders.TYPE, String.class);
        if (jmsType != null) {
            try {
                jmsMessage.setJMSType(jmsType);
            } catch (Exception ex) {
                logger.debug("Failed to set JMSType - skipping", ex);
            }
        }
        for (Map.Entry<String, Object> entry : headers.entrySet()) {
            String headerName = entry.getKey();
            if (StringUtils.hasText(headerName) && !headerName.startsWith(JmsHeaders.PREFIX)) {
                Object value = entry.getValue();
                if (value != null && SUPPORTED_PROPERTY_TYPES.contains(value.getClass())) {
                    try {
                        String propertyName = this.fromHeaderName(headerName);
                        jmsMessage.setObjectProperty(propertyName, value);
                    } catch (Exception ex) {
                        if (headerName.startsWith("JMSX")) {
                            if (logger.isTraceEnabled()) {
                                logger.trace("Skipping reserved header '" + headerName + "' since it cannot be set by client");
                            }
                        } else if (logger.isDebugEnabled()) {
                            logger.debug("Failed to map message header '" + headerName + "' to JMS property", ex);
                        }
                    }
                }
            }
        }
    } catch (Exception ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Error occurred while mapping from MessageHeaders to JMS properties", ex);
        }
    }
}
Also used : Destination(jakarta.jms.Destination) Map(java.util.Map) HashMap(java.util.HashMap) JMSException(jakarta.jms.JMSException)

Example 25 with Destination

use of jakarta.jms.Destination in project spring-framework by spring-projects.

the class SimpleJmsHeaderMapper method toHeaders.

@Override
public MessageHeaders toHeaders(jakarta.jms.Message jmsMessage) {
    Map<String, Object> headers = new HashMap<>();
    try {
        try {
            String correlationId = jmsMessage.getJMSCorrelationID();
            if (correlationId != null) {
                headers.put(JmsHeaders.CORRELATION_ID, correlationId);
            }
        } catch (Exception ex) {
            logger.debug("Failed to read JMSCorrelationID property - skipping", ex);
        }
        try {
            Destination destination = jmsMessage.getJMSDestination();
            if (destination != null) {
                headers.put(JmsHeaders.DESTINATION, destination);
            }
        } catch (Exception ex) {
            logger.debug("Failed to read JMSDestination property - skipping", ex);
        }
        try {
            int deliveryMode = jmsMessage.getJMSDeliveryMode();
            headers.put(JmsHeaders.DELIVERY_MODE, deliveryMode);
        } catch (Exception ex) {
            logger.debug("Failed to read JMSDeliveryMode property - skipping", ex);
        }
        try {
            long expiration = jmsMessage.getJMSExpiration();
            headers.put(JmsHeaders.EXPIRATION, expiration);
        } catch (Exception ex) {
            logger.debug("Failed to read JMSExpiration property - skipping", ex);
        }
        try {
            String messageId = jmsMessage.getJMSMessageID();
            if (messageId != null) {
                headers.put(JmsHeaders.MESSAGE_ID, messageId);
            }
        } catch (Exception ex) {
            logger.debug("Failed to read JMSMessageID property - skipping", ex);
        }
        try {
            headers.put(JmsHeaders.PRIORITY, jmsMessage.getJMSPriority());
        } catch (Exception ex) {
            logger.debug("Failed to read JMSPriority property - skipping", ex);
        }
        try {
            Destination replyTo = jmsMessage.getJMSReplyTo();
            if (replyTo != null) {
                headers.put(JmsHeaders.REPLY_TO, replyTo);
            }
        } catch (Exception ex) {
            logger.debug("Failed to read JMSReplyTo property - skipping", ex);
        }
        try {
            headers.put(JmsHeaders.REDELIVERED, jmsMessage.getJMSRedelivered());
        } catch (Exception ex) {
            logger.debug("Failed to read JMSRedelivered property - skipping", ex);
        }
        try {
            String type = jmsMessage.getJMSType();
            if (type != null) {
                headers.put(JmsHeaders.TYPE, type);
            }
        } catch (Exception ex) {
            logger.debug("Failed to read JMSType property - skipping", ex);
        }
        try {
            headers.put(JmsHeaders.TIMESTAMP, jmsMessage.getJMSTimestamp());
        } catch (Exception ex) {
            logger.debug("Failed to read JMSTimestamp property - skipping", ex);
        }
        Enumeration<?> jmsPropertyNames = jmsMessage.getPropertyNames();
        if (jmsPropertyNames != null) {
            while (jmsPropertyNames.hasMoreElements()) {
                String propertyName = jmsPropertyNames.nextElement().toString();
                try {
                    String headerName = this.toHeaderName(propertyName);
                    headers.put(headerName, jmsMessage.getObjectProperty(propertyName));
                } catch (Exception ex) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Error occurred while mapping JMS property '" + propertyName + "' to Message header", ex);
                    }
                }
            }
        }
    } catch (JMSException ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Error occurred while mapping from JMS properties to MessageHeaders", ex);
        }
    }
    return new MessageHeaders(headers);
}
Also used : Destination(jakarta.jms.Destination) HashMap(java.util.HashMap) JMSException(jakarta.jms.JMSException) MessageHeaders(org.springframework.messaging.MessageHeaders) JMSException(jakarta.jms.JMSException)

Aggregations

Destination (jakarta.jms.Destination)41 Test (org.junit.jupiter.api.Test)31 StubTextMessage (org.springframework.jms.StubTextMessage)11 Session (jakarta.jms.Session)8 TextMessage (jakarta.jms.TextMessage)5 JMSException (jakarta.jms.JMSException)3 HashMap (java.util.HashMap)3 DestinationResolutionException (org.springframework.jms.support.destination.DestinationResolutionException)3 DestinationResolver (org.springframework.jms.support.destination.DestinationResolver)3 MessageProducer (jakarta.jms.MessageProducer)2 QueueSender (jakarta.jms.QueueSender)2 NamingException (javax.naming.NamingException)2 StubQueue (org.springframework.jms.StubQueue)2 Connection (jakarta.jms.Connection)1 ConnectionFactory (jakarta.jms.ConnectionFactory)1 Message (jakarta.jms.Message)1 MessageConsumer (jakarta.jms.MessageConsumer)1 Map (java.util.Map)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 JmsTemplate (org.springframework.jms.core.JmsTemplate)1