use of javax.jms.MessageConsumer in project sling by apache.
the class ActiveMQConnectionFactoryServiceTest method testGetConnectionFactory.
@Test
public void testGetConnectionFactory() throws Exception {
LOGGER.info("Starting test");
ActiveMQConnectionFactoryService cfs = ActiveMQConnectionFactoryServiceTest.activate();
ConnectionFactory cf = cfs.getConnectionFactory();
Connection connection = cf.createConnection();
Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
Topic t = session.createTopic("testTopic");
MessageConsumer consumer = session.createConsumer(t);
LOGGER.info("Starting connection");
connection.start();
LOGGER.info("Connection started.. sending message");
session.createProducer(t).send(session.createTextMessage("testing with a message"));
session.commit();
LOGGER.info("Message sent ... receiving message");
Message m = consumer.receive();
LOGGER.info("Message received");
assertTrue(m instanceof TextMessage);
assertEquals("testing with a message", ((TextMessage) m).getText());
session.close();
connection.stop();
deactivate(cfs);
}
use of javax.jms.MessageConsumer in project hive by apache.
the class TestNotificationListener method setUp.
@Before
public void setUp() throws Exception {
System.setProperty("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
System.setProperty("java.naming.provider.url", "vm://localhost?broker.persistent=false");
ConnectionFactory connFac = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
Connection conn = connFac.createConnection();
conn.start();
// We want message to be sent when session commits, thus we run in
// transacted mode.
Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
Destination hcatTopic = session.createTopic(HCatConstants.HCAT_DEFAULT_TOPIC_PREFIX);
MessageConsumer consumer1 = session.createConsumer(hcatTopic);
consumer1.setMessageListener(this);
Destination tblTopic = session.createTopic(HCatConstants.HCAT_DEFAULT_TOPIC_PREFIX + ".mydb.mytbl");
MessageConsumer consumer2 = session.createConsumer(tblTopic);
consumer2.setMessageListener(this);
Destination dbTopic = session.createTopic(HCatConstants.HCAT_DEFAULT_TOPIC_PREFIX + ".mydb");
MessageConsumer consumer3 = session.createConsumer(dbTopic);
consumer3.setMessageListener(this);
setUpHiveConf();
hiveConf.set(ConfVars.METASTORE_EVENT_LISTENERS.varname, NotificationListener.class.getName());
hiveConf.setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, "org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory");
SessionState.start(new CliSessionState(hiveConf));
driver = DriverFactory.newDriver(hiveConf);
client = new HiveMetaStoreClient(hiveConf);
}
use of javax.jms.MessageConsumer in project gocd by gocd.
the class ActiveMqMessagingService method addQueueListener.
public JMSMessageListenerAdapter addQueueListener(String queueName, final GoMessageListener listener) {
try {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(session.createQueue(queueName));
return JMSMessageListenerAdapter.startListening(consumer, listener, daemonThreadStatsCollector);
} catch (Exception e) {
throw bomb(e);
}
}
use of javax.jms.MessageConsumer in project cxf by apache.
the class MessageListenerTest method drainQueue.
protected void drainQueue(Connection connection, Queue dest) throws JMSException, InterruptedException {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(dest);
while (consumer.receiveNoWait() != null) {
System.out.println("Consuming old message");
}
consumer.close();
session.close();
assertNumMessagesInQueue("", connection, dest, 0, 0);
}
use of javax.jms.MessageConsumer in project cxf by apache.
the class TestReceiver method receiveAndRespond.
private void receiveAndRespond() {
try (ResourceCloser closer = new ResourceCloser()) {
Connection connection = closer.register(connectionFactory.createConnection());
connection.start();
Session session = closer.register(connection.createSession(false, Session.AUTO_ACKNOWLEDGE));
MessageConsumer consumer = closer.register(session.createConsumer(session.createQueue(receiveQueueName)));
final javax.jms.Message inMessage = consumer.receive(10000);
if (inMessage == null) {
// System.out.println("TestReceiver timed out");
throw new RuntimeException("No message received on destination " + receiveQueueName);
}
requestMessageId = inMessage.getJMSMessageID();
// System.out.println("Received message " + requestMessageId);
final TextMessage replyMessage = session.createTextMessage("Result");
String correlationId = (forceMessageIdAsCorrelationId || inMessage.getJMSCorrelationID() == null) ? inMessage.getJMSMessageID() : inMessage.getJMSCorrelationID();
replyMessage.setJMSCorrelationID(correlationId);
Destination replyDest = staticReplyQueue != null ? session.createQueue(staticReplyQueue) : inMessage.getJMSReplyTo();
if (replyDest != null) {
final MessageProducer producer = closer.register(session.createProducer(replyDest));
// System.out.println("Sending reply with correlation id " + correlationId + " to " + replyDest);
producer.send(replyMessage);
}
} catch (Throwable e) {
ex = e;
}
}
Aggregations