use of javax.jms.ConnectionFactory 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);
}
use of javax.jms.ConnectionFactory 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.ConnectionFactory in project karaf by apache.
the class JmsConnector method connect.
public Connection connect() throws JMSException {
reference = this.lookupConnectionFactory(connectionFactoryName);
ConnectionFactory cf = bc.getService(reference);
connection = cf.createConnection(username, password);
connection.start();
return connection;
}
use of javax.jms.ConnectionFactory in project wildfly by wildfly.
the class HelloBean method sendMessage.
public String sendMessage() throws Exception {
String destinationName = "java:jboss/exported/queue/TestQueue";
Context ic = null;
ConnectionFactory cf = null;
Connection connection = null;
try {
ic = getInitialContext();
cf = (ConnectionFactory) ic.lookup("java:/ConnectionFactory");
Queue queue = (Queue) ic.lookup(destinationName);
connection = cf.createConnection("guest", "guest");
// we need to start connection for consumer
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer sender = session.createProducer(queue);
TextMessage message = session.createTextMessage("hello goodbye");
TemporaryQueue replyQueue = session.createTemporaryQueue();
message.setJMSReplyTo(replyQueue);
sender.send(message);
MessageConsumer consumer = session.createConsumer(replyQueue);
TextMessage replyMsg = (TextMessage) consumer.receive(5000);
log.trace("Message received:" + replyMsg);
return replyMsg.getText();
} finally {
if (ic != null) {
try {
ic.close();
} catch (Exception ignore) {
}
}
closeConnection(connection);
}
}
use of javax.jms.ConnectionFactory in project wildfly by wildfly.
the class RunAsTestCaseEJBMDB method testSendMessage.
@Test
public void testSendMessage() throws Exception {
ConnectionFactory cf = null;
Connection connection = null;
Session session = null;
try {
cf = (ConnectionFactory) initialContext.lookup("jms/RemoteConnectionFactory");
Queue queue = (Queue) initialContext.lookup(QUEUE_NAME);
connection = cf.createConnection("guest", "guest");
//for consumer we need to start connection
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer sender = session.createProducer(queue);
TemporaryQueue replyQueue = session.createTemporaryQueue();
TextMessage message = session.createTextMessage("hello goodbye");
message.setJMSReplyTo(replyQueue);
sender.send(message);
log.trace("testSendMessage(): Message sent!");
MessageConsumer consumer = session.createConsumer(replyQueue);
Message replyMsg = consumer.receive(5000);
Assert.assertNotNull(replyMsg);
Assert.assertTrue(replyMsg instanceof TextMessage);
String actual = ((TextMessage) replyMsg).getText();
Assert.assertEquals("Howdy Fred! GoodBye user1", actual);
} finally {
if (session != null) {
session.close();
}
closeConnection(connection);
}
}
Aggregations