Search in sources :

Example 11 with Message

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

the class JmsSpout method nextTuple.

public void nextTuple() {
    Message msg = this.queue.poll();
    if (msg == null) {
        Utils.sleep(50);
    } else {
        LOG.debug("sending tuple: " + msg);
        // get the tuple from the handler
        try {
            Values vals = this.tupleProducer.toTuple(msg);
            // ack if we're not in AUTO_ACKNOWLEDGE mode, or the message requests ACKNOWLEDGE
            LOG.debug("Requested deliveryMode: " + toDeliveryModeString(msg.getJMSDeliveryMode()));
            LOG.debug("Our deliveryMode: " + toDeliveryModeString(this.jmsAcknowledgeMode));
            if (this.isDurableSubscription()) {
                LOG.debug("Requesting acks.");
                JmsMessageID messageId = new JmsMessageID(this.messageSequence++, msg.getJMSMessageID());
                this.collector.emit(vals, messageId);
                // at this point we successfully emitted. Store
                // the message and message ID so we can do a
                // JMS acknowledge later
                this.pendingMessages.put(messageId, msg);
                this.toCommit.add(messageId);
            } else {
                this.collector.emit(vals);
            }
        } catch (JMSException e) {
            LOG.warn("Unable to convert JMS message: " + msg);
        }
    }
}
Also used : Message(javax.jms.Message) Values(org.apache.storm.tuple.Values) JMSException(javax.jms.JMSException)

Example 12 with Message

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

the class NotificationListener method isConnectionHealthy.

/**
   * Send a dummy message to probe if the JMS connection is healthy
   * @return true if connection is healthy, false otherwise
   */
protected boolean isConnectionHealthy() {
    try {
        Topic topic = createTopic(getTopicPrefix(getConf()) + "." + HEALTH_CHECK_TOPIC_SUFFIX);
        MessageProducer producer = createProducer(topic);
        Message msg = session.get().createTextMessage(HEALTH_CHECK_MSG);
        producer.send(msg, DeliveryMode.NON_PERSISTENT, 4, 0);
    } catch (Exception e) {
        return false;
    }
    return true;
}
Also used : HCatEventMessage(org.apache.hive.hcatalog.messaging.HCatEventMessage) Message(javax.jms.Message) MessageProducer(javax.jms.MessageProducer) Topic(javax.jms.Topic) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) NamingException(javax.naming.NamingException) JMSException(javax.jms.JMSException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException)

Example 13 with Message

use of javax.jms.Message in project javaee7-samples by javaee-samples.

the class ClassicMessageReceiver method receiveMessage.

public String receiveMessage() {
    String response = null;
    Connection connection = null;
    try {
        connection = connectionFactory.createConnection();
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer messageConsumer = session.createConsumer(demoQueue);
        Message message = messageConsumer.receive(5000);
        response = message.getBody(String.class);
    } catch (JMSException ex) {
        ex.printStackTrace();
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException ex) {
                ex.printStackTrace();
            }
        }
    }
    return response;
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) Connection(javax.jms.Connection) JMSException(javax.jms.JMSException) Session(javax.jms.Session)

Example 14 with Message

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

the class JMSClient method sendToActiveMQ.

private static void sendToActiveMQ() throws Exception {
    ConnectionFactory cf = new ActiveMQConnectionFactory(AMQ_USER, AMQ_PASSWD, AMQ_BROKER_URL);
    Connection conn = cf.createConnection();
    try {
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        final MessageProducer producer = session.createProducer(session.createQueue(QUEUE_NAME));
        BufferedReader reader = new BufferedReader(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(MESSAGE_PAYLOAD)));
        StringBuilder buf = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            buf.append(line);
        }
        reader.close();
        Message message = session.createTextMessage(buf.toString());
        producer.send(message);
        System.out.println("Message sent. Please see server console output");
    } finally {
        conn.close();
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) InputStreamReader(java.io.InputStreamReader) Message(javax.jms.Message) Connection(javax.jms.Connection) BufferedReader(java.io.BufferedReader) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session)

Example 15 with Message

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

the class JMSClient method sendToHornetQ.

private static void sendToHornetQ(String value) throws Exception {
    HornetQMixIn hqMixIn = new HornetQMixIn(false).setUser(USER).setPassword(PASSWD);
    hqMixIn.initialize();
    try {
        Session session = hqMixIn.getJMSSession();
        final MessageProducer producer = session.createProducer(HornetQMixIn.getJMSQueue(REQUEST_NAME));
        final MessageConsumer consumer = session.createConsumer(HornetQMixIn.getJMSQueue(REPLY_NAME));
        producer.send(hqMixIn.createJMSMessage(createPayload(value)));
        System.out.println("Message sent. Waiting for reply ...");
        Message message = consumer.receive(3000);
        String reply = hqMixIn.readStringFromJMSMessage(message);
        System.out.println("REPLY: \n" + reply);
    } finally {
        hqMixIn.uninitialize();
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) MessageProducer(javax.jms.MessageProducer) HornetQMixIn(org.switchyard.component.test.mixins.hornetq.HornetQMixIn) Session(javax.jms.Session)

Aggregations

Message (javax.jms.Message)191 TextMessage (javax.jms.TextMessage)91 Test (org.junit.Test)84 Session (javax.jms.Session)73 JMSException (javax.jms.JMSException)59 MessageProducer (javax.jms.MessageProducer)53 ObjectMessage (javax.jms.ObjectMessage)46 MessageConsumer (javax.jms.MessageConsumer)40 Connection (javax.jms.Connection)38 BytesMessage (javax.jms.BytesMessage)31 Destination (javax.jms.Destination)27 MapMessage (javax.jms.MapMessage)25 Queue (javax.jms.Queue)20 QueueSession (javax.jms.QueueSession)17 ConnectionFactory (javax.jms.ConnectionFactory)16 MessageCreator (org.springframework.jms.core.MessageCreator)12 MessageListener (javax.jms.MessageListener)9 AMQPMessage (org.apache.qpid.qmf2.common.AMQPMessage)9 Map (java.util.Map)8 QueueConnection (javax.jms.QueueConnection)8