use of javax.jms.MessageConsumer 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);
}
}
use of javax.jms.MessageConsumer 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.MessageConsumer 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();
}
}
use of javax.jms.MessageConsumer in project quickstarts by jboss-switchyard.
the class JMSClient method sendToActiveMQ.
private static void sendToActiveMQ(String value) 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(REQUEST_NAME));
final MessageConsumer consumer = session.createConsumer(session.createQueue(REPLY_NAME));
conn.start();
producer.send(session.createTextMessage(createPayload(value)));
System.out.println("Message sent. Waiting for reply ...");
Message message = consumer.receive(3000);
String reply = ((TextMessage) message).getText();
System.out.println("REPLY: \n" + reply);
} finally {
conn.close();
}
}
use of javax.jms.MessageConsumer in project quickstarts by jboss-switchyard.
the class OrderIntakeClient method main.
/**
* Main routing for OrderIntakeClient
* @param args command-line args
* @throws Exception if something goes wrong.
*/
public static void main(final String[] args) throws Exception {
HornetQMixIn hqMixIn = new HornetQMixIn(false).setUser(USER).setPassword(PASSWD);
hqMixIn.initialize();
try {
Session session = hqMixIn.getJMSSession();
MessageProducer producer = session.createProducer(HornetQMixIn.getJMSQueue(ORDER_QUEUE_NAME));
String orderTxt = readFileContent(args[0]);
System.out.println("Submitting Order" + "\n" + "----------------------------\n" + orderTxt + "\n----------------------------");
producer.send(hqMixIn.createJMSMessage(orderTxt));
MessageConsumer consumer = session.createConsumer(HornetQMixIn.getJMSQueue(ORDERACK_QUEUE_NAME));
System.out.println("Order submitted ... waiting for reply.");
TextMessage reply = (TextMessage) consumer.receive(3000);
if (reply == null) {
System.out.println("No reply received.");
} else {
System.out.println("Received reply" + "\n" + "----------------------------\n" + reply.getText() + "\n----------------------------");
}
} finally {
hqMixIn.uninitialize();
}
}
Aggregations