use of javax.jms.QueueConnectionFactory in project spring-framework by spring-projects.
the class TransactionAwareConnectionFactoryProxy method createQueueConnection.
@Override
public QueueConnection createQueueConnection() throws JMSException {
ConnectionFactory target = obtainTargetConnectionFactory();
if (!(target instanceof QueueConnectionFactory)) {
throw new javax.jms.IllegalStateException("'targetConnectionFactory' is no QueueConnectionFactory");
}
QueueConnection targetConnection = ((QueueConnectionFactory) target).createQueueConnection();
return (QueueConnection) getTransactionAwareConnectionProxy(targetConnection);
}
use of javax.jms.QueueConnectionFactory in project jmeter by apache.
the class JMSSampler method threadStarted.
@Override
public void threadStarted() {
logThreadStart();
thrown = null;
try {
context = getInitialContext();
Object obj = context.lookup(getQueueConnectionFactory());
if (!(obj instanceof QueueConnectionFactory)) {
String msg = "QueueConnectionFactory expected, but got " + (obj != null ? obj.getClass().getName() : "null");
LOGGER.error(msg);
throw new IllegalStateException(msg);
}
QueueConnectionFactory factory = (QueueConnectionFactory) obj;
Queue sendQueue = (Queue) context.lookup(getSendQueue());
if (!useTemporyQueue()) {
receiveQueue = (Queue) context.lookup(getReceiveQueue());
receiverThread = Receiver.createReceiver(factory, receiveQueue, Utils.getFromEnvironment(context, Context.SECURITY_PRINCIPAL), Utils.getFromEnvironment(context, Context.SECURITY_CREDENTIALS), isUseResMsgIdAsCorrelId(), getJMSSelector());
}
String principal = null;
String credentials = null;
if (USE_SECURITY_PROPERTIES) {
principal = Utils.getFromEnvironment(context, Context.SECURITY_PRINCIPAL);
credentials = Utils.getFromEnvironment(context, Context.SECURITY_CREDENTIALS);
}
if (principal != null && credentials != null) {
connection = factory.createQueueConnection(principal, credentials);
} else {
connection = factory.createQueueConnection();
}
session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
LOGGER.debug("Session created");
if (isOneway()) {
producer = session.createSender(sendQueue);
if (isNonPersistent()) {
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
}
producer.setPriority(Integer.parseInt(getPriority()));
producer.setTimeToLive(Long.parseLong(getExpiration()));
} else {
if (useTemporyQueue()) {
executor = new TemporaryQueueExecutor(session, sendQueue);
} else {
producer = session.createSender(sendQueue);
executor = new FixedQueueExecutor(producer, getTimeoutAsInt(), isUseReqMsgIdAsCorrelId());
}
}
LOGGER.debug("Starting connection");
connection.start();
LOGGER.debug("Connection started");
} catch (Exception | NoClassDefFoundError e) {
thrown = e;
LOGGER.error(e.getLocalizedMessage(), e);
}
}
use of javax.jms.QueueConnectionFactory in project wildfly by wildfly.
the class GetCallerPrincipalTestCase method testMDBLifecycle.
/**
* Run this one in the container so it can lookup the queue
* @throws Exception
*/
@OperateOnDeployment("test")
@Test
public void testMDBLifecycle() throws Exception {
deployer.deploy("mdb");
SecurityClient client = this.login();
ITestResultsSingleton results = this.getResultsSingleton();
MessageProducer producer = null;
MessageConsumer consumer = null;
QueueConnection conn = null;
Session session = null;
try {
QueueConnectionFactory qcf = (QueueConnectionFactory) new InitialContext().lookup("java:/ConnectionFactory");
Queue queue = (Queue) new InitialContext().lookup("java:jboss/" + QUEUE_NAME);
conn = qcf.createQueueConnection("guest", "guest");
conn.start();
session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
TemporaryQueue replyQueue = session.createTemporaryQueue();
TextMessage msg = session.createTextMessage("Hello world");
msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
msg.setJMSReplyTo(replyQueue);
producer = session.createProducer(queue);
producer.send(msg);
consumer = session.createConsumer(replyQueue);
Message replyMsg = consumer.receive(5000);
Object obj = ((ObjectMessage) replyMsg).getObject();
log.trace("MDB message get: " + obj);
Assert.assertEquals(OK + "start", results.getMdb("postconstruct"));
deployer.undeploy("mdb");
Assert.assertEquals(OK + "stop", results.getMdb("predestroy"));
} finally {
if (consumer != null) {
consumer.close();
}
if (producer != null) {
producer.close();
}
if (session != null) {
session.close();
}
if (conn != null) {
conn.close();
}
client.logout();
}
}
use of javax.jms.QueueConnectionFactory in project tomee by apache.
the class ContextLookupStatefulPojoBean method lookupJMSConnectionFactory.
public void lookupJMSConnectionFactory() throws TestFailureException {
try {
try {
Object obj = ejbContext.lookup("jms");
Assert.assertNotNull("The JMS ConnectionFactory is null", obj);
Assert.assertTrue("Not an instance of ConnectionFactory", obj instanceof ConnectionFactory);
final ConnectionFactory connectionFactory = (ConnectionFactory) obj;
testJmsConnection(connectionFactory.createConnection());
obj = ejbContext.lookup("TopicCF");
Assert.assertNotNull("The JMS TopicConnectionFactory is null", obj);
Assert.assertTrue("Not an instance of TopicConnectionFactory", obj instanceof TopicConnectionFactory);
final TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) obj;
testJmsConnection(topicConnectionFactory.createConnection());
obj = ejbContext.lookup("QueueCF");
Assert.assertNotNull("The JMS QueueConnectionFactory is null", obj);
Assert.assertTrue("Not an instance of QueueConnectionFactory", obj instanceof QueueConnectionFactory);
final QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) obj;
testJmsConnection(queueConnectionFactory.createConnection());
} catch (final Exception e) {
e.printStackTrace();
Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
use of javax.jms.QueueConnectionFactory in project tomee by apache.
the class ContextLookupStatelessBean method lookupJMSConnectionFactory.
public void lookupJMSConnectionFactory() throws TestFailureException {
try {
try {
Object obj = ejbContext.lookup("jms");
Assert.assertNotNull("The JMS ConnectionFactory is null", obj);
Assert.assertTrue("Not an instance of ConnectionFactory", obj instanceof ConnectionFactory);
final ConnectionFactory connectionFactory = (ConnectionFactory) obj;
testJmsConnection(connectionFactory.createConnection());
obj = ejbContext.lookup("TopicCF");
Assert.assertNotNull("The JMS TopicConnectionFactory is null", obj);
Assert.assertTrue("Not an instance of TopicConnectionFactory", obj instanceof TopicConnectionFactory);
final TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) obj;
testJmsConnection(topicConnectionFactory.createConnection());
obj = ejbContext.lookup("QueueCF");
Assert.assertNotNull("The JMS QueueConnectionFactory is null", obj);
Assert.assertTrue("Not an instance of QueueConnectionFactory", obj instanceof QueueConnectionFactory);
final QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) obj;
testJmsConnection(queueConnectionFactory.createConnection());
} catch (final Exception e) {
e.printStackTrace();
Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
Aggregations