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);
}
}
}
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;
}
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;
}
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();
}
}
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();
}
}
Aggregations