Search in sources :

Example 31 with Destination

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

the class TopicMDB method onMessage.

public void onMessage(final Message m) {
    try {
        TextMessage message = (TextMessage) m;
        Destination replyTo = m.getJMSReplyTo();
        context.createProducer().setJMSCorrelationID(message.getJMSMessageID()).send(replyTo, message.getText());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Destination(javax.jms.Destination) TextMessage(javax.jms.TextMessage)

Example 32 with Destination

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

the class ExportImportJournalTestCase method sendMessage.

protected static void sendMessage(Context ctx, String destinationLookup, String text) throws NamingException, JMSException {
    ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
    assertNotNull(cf);
    Destination destination = (Destination) ctx.lookup(destinationLookup);
    assertNotNull(destination);
    try (JMSContext context = cf.createContext("guest", "guest")) {
        TextMessage message = context.createTextMessage(text);
        message.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
        context.createProducer().send(destination, message);
    }
}
Also used : Destination(javax.jms.Destination) ConnectionFactory(javax.jms.ConnectionFactory) JMSContext(javax.jms.JMSContext) TextMessage(javax.jms.TextMessage)

Example 33 with Destination

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

the class ExportImportJournalTestCase method receiveMessage.

protected static void receiveMessage(Context ctx, String destinationLookup, boolean expectReceivedMessage, String expectedText) throws NamingException {
    ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
    assertNotNull(cf);
    Destination destination = (Destination) ctx.lookup(destinationLookup);
    assertNotNull(destination);
    try (JMSContext context = cf.createContext("guest", "guest")) {
        JMSConsumer consumer = context.createConsumer(destination);
        String text = consumer.receiveBody(String.class, 5000);
        if (expectReceivedMessage) {
            assertNotNull(text);
            assertEquals(expectedText, text);
        } else {
            assertNull("should not have received any message", text);
        }
    }
}
Also used : Destination(javax.jms.Destination) ConnectionFactory(javax.jms.ConnectionFactory) JMSConsumer(javax.jms.JMSConsumer) JMSContext(javax.jms.JMSContext)

Example 34 with Destination

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

the class SimpleJmsHeaderMapper method fromHeaders.

@Override
public void fromHeaders(MessageHeaders headers, javax.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.info("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.info("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.info("Failed to set JMSType - skipping", ex);
            }
        }
        Set<String> headerNames = headers.keySet();
        for (String headerName : headerNames) {
            if (StringUtils.hasText(headerName) && !headerName.startsWith(JmsHeaders.PREFIX)) {
                Object value = headers.get(headerName);
                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.isWarnEnabled()) {
                            logger.warn("Failed to map message header '" + headerName + "' to JMS property", ex);
                        }
                    }
                }
            }
        }
    } catch (Exception ex) {
        if (logger.isWarnEnabled()) {
            logger.warn("Error occurred while mapping from MessageHeaders to JMS properties", ex);
        }
    }
}
Also used : Destination(javax.jms.Destination) JMSException(javax.jms.JMSException)

Example 35 with Destination

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

the class AbstractAdaptableMessageListener method getResponseDestination.

private Destination getResponseDestination(Message request, Message response, Session session, Object result) throws JMSException {
    if (result instanceof JmsResponse) {
        JmsResponse<?> jmsResponse = (JmsResponse) result;
        Destination destination = jmsResponse.resolveDestination(getDestinationResolver(), session);
        if (destination != null) {
            return destination;
        }
    }
    return getResponseDestination(request, response, session);
}
Also used : Destination(javax.jms.Destination)

Aggregations

Destination (javax.jms.Destination)178 Test (org.junit.Test)51 TextMessage (javax.jms.TextMessage)47 Session (javax.jms.Session)46 JMSException (javax.jms.JMSException)45 Connection (javax.jms.Connection)32 MessageProducer (javax.jms.MessageProducer)31 Message (javax.jms.Message)30 ConnectionFactory (javax.jms.ConnectionFactory)24 MessageConsumer (javax.jms.MessageConsumer)24 JMSContext (javax.jms.JMSContext)16 CountDownLatch (java.util.concurrent.CountDownLatch)15 ObjectMessage (javax.jms.ObjectMessage)12 StubTextMessage (org.springframework.jms.StubTextMessage)11 InitialContext (javax.naming.InitialContext)10 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)10 Queue (javax.jms.Queue)8 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)8 MapMessage (javax.jms.MapMessage)7 HashMap (java.util.HashMap)6