Search in sources :

Example 11 with Destination

use of javax.jms.Destination in project storm by apache.

the class JmsSpout method open.

/**
     * <code>ISpout</code> implementation.
     * <p>
     * Connects the JMS spout to the configured JMS destination
     * topic/queue.
     */
@SuppressWarnings("rawtypes")
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
    if (this.jmsProvider == null) {
        throw new IllegalStateException("JMS provider has not been set.");
    }
    if (this.tupleProducer == null) {
        throw new IllegalStateException("JMS Tuple Producer has not been set.");
    }
    Integer topologyTimeout = (Integer) conf.get("topology.message.timeout.secs");
    // TODO fine a way to get the default timeout from storm, so we're not hard-coding to 30 seconds (it could change)
    topologyTimeout = topologyTimeout == null ? 30 : topologyTimeout;
    if ((topologyTimeout.intValue() * 1000) > this.recoveryPeriod) {
        LOG.warn("*** WARNING *** : " + "Recovery period (" + this.recoveryPeriod + " ms.) is less then the configured " + "'topology.message.timeout.secs' of " + topologyTimeout + " secs. This could lead to a message replay flood!");
    }
    this.queue = new LinkedBlockingQueue<Message>();
    this.toCommit = new TreeSet<JmsMessageID>();
    this.pendingMessages = new HashMap<JmsMessageID, Message>();
    this.collector = collector;
    try {
        ConnectionFactory cf = this.jmsProvider.connectionFactory();
        Destination dest = this.jmsProvider.destination();
        this.connection = cf.createConnection();
        this.session = connection.createSession(false, this.jmsAcknowledgeMode);
        MessageConsumer consumer = session.createConsumer(dest);
        consumer.setMessageListener(this);
        this.connection.start();
        if (this.isDurableSubscription() && this.recoveryPeriod > 0) {
            this.recoveryTimer = new Timer();
            this.recoveryTimer.scheduleAtFixedRate(new RecoveryTask(), 10, this.recoveryPeriod);
        }
    } catch (Exception e) {
        LOG.warn("Error creating JMS connection.", e);
    }
}
Also used : Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) JMSException(javax.jms.JMSException) ConnectionFactory(javax.jms.ConnectionFactory)

Example 12 with Destination

use of javax.jms.Destination in project hive by apache.

the class TestMsgBusConnection method connectClient.

private void connectClient() throws JMSException {
    ConnectionFactory connFac = new ActiveMQConnectionFactory("tcp://localhost:61616");
    Connection conn = connFac.createConnection();
    conn.start();
    Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
    Destination hcatTopic = session.createTopic("planetlab.hcat");
    consumer = session.createConsumer(hcatTopic);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Destination(javax.jms.Destination) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) Connection(javax.jms.Connection) Session(javax.jms.Session)

Example 13 with Destination

use of javax.jms.Destination in project quickstarts by jboss-switchyard.

the class CamelAmqpBindingTest method sentTextToQueue.

private void sentTextToQueue(String payload) throws Exception {
    Session session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = _mixin.getDestination(AMQPMixIn.DEFAULT_QUEUE_JNDI_LOCATION);
    MessageProducer messageProducer = session.createProducer(destination);
    TextMessage message = session.createTextMessage(payload);
    messageProducer.send(message);
    session.close();
}
Also used : Destination(javax.jms.Destination) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Example 14 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 15 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)137 Test (org.junit.Test)41 TextMessage (javax.jms.TextMessage)38 JMSException (javax.jms.JMSException)33 Message (javax.jms.Message)27 Session (javax.jms.Session)27 MessageProducer (javax.jms.MessageProducer)22 Connection (javax.jms.Connection)15 ConnectionFactory (javax.jms.ConnectionFactory)15 JMSContext (javax.jms.JMSContext)15 CountDownLatch (java.util.concurrent.CountDownLatch)13 MessageConsumer (javax.jms.MessageConsumer)12 StubTextMessage (org.springframework.jms.StubTextMessage)11 ObjectMessage (javax.jms.ObjectMessage)10 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)10 MapMessage (javax.jms.MapMessage)7 Queue (javax.jms.Queue)7 Map (java.util.Map)6 HashMap (java.util.HashMap)5 JMSConsumer (javax.jms.JMSConsumer)5