use of javax.jms.JMSContext in project activemq-artemis by apache.
the class JMSContextTest method sessionTransactedTestNoActiveJTATx.
@Test
public void sessionTransactedTestNoActiveJTATx() throws Exception {
((DummyTransactionManager) ServiceUtils.getTransactionManager()).tx = new DummyTransaction();
JMSContext context = qraConnectionFactory.createContext(JMSContext.SESSION_TRANSACTED);
assertEquals(context.getSessionMode(), JMSContext.AUTO_ACKNOWLEDGE);
}
use of javax.jms.JMSContext in project activemq-artemis by apache.
the class JMSContextTest method clientAckTestNoActiveJTATx.
@Test
public void clientAckTestNoActiveJTATx() throws Exception {
((DummyTransactionManager) ServiceUtils.getTransactionManager()).tx = new DummyTransaction();
JMSContext context = qraConnectionFactory.createContext(JMSContext.CLIENT_ACKNOWLEDGE);
assertEquals(context.getSessionMode(), JMSContext.AUTO_ACKNOWLEDGE);
}
use of javax.jms.JMSContext in project activemq-artemis by apache.
the class OutgoingConnectionJTATest method testSimpleSendNoXAJMSContext.
@Test
public void testSimpleSendNoXAJMSContext() throws Exception {
Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
try (ClientSessionFactory sf = locator.createSessionFactory();
ClientSession session = sf.createSession();
ClientConsumer consVerify = session.createConsumer(MDBQUEUE);
JMSContext jmsctx = qraConnectionFactory.createContext()) {
session.start();
// These next 4 lines could be written in a single line however it makes difficult for debugging
JMSProducer producer = jmsctx.createProducer();
producer.setProperty("strvalue", "hello");
TextMessage msgsend = jmsctx.createTextMessage("hello");
producer.send(q, msgsend);
ClientMessage msg = consVerify.receive(1000);
assertNotNull(msg);
assertEquals("hello", msg.getStringProperty("strvalue"));
}
}
use of javax.jms.JMSContext in project activemq-artemis by apache.
the class ActiveMQServerTestCase method tearDown.
@After
public void tearDown() throws Exception {
for (JMSContext context : contextSet) {
context.close();
}
contextSet.clear();
for (Connection localConn : connectionsSet) {
localConn.close();
}
connectionsSet.clear();
}
use of javax.jms.JMSContext in project activemq-artemis by apache.
the class JMSAutoCloseableExample method main.
public static void main(final String[] args) throws Exception {
// Step 2. Perfom a lookup on the queue
Queue queue = ActiveMQJMSClient.createQueue("exampleQueue");
// Step 4.Create a JMS Context using the try-with-resources statement
try (// Even though ConnectionFactory is not closeable it would be nice to close an ActiveMQConnectionFactory
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory();
JMSContext jmsContext = cf.createContext()) {
// Step 5. create a jms producer
JMSProducer jmsProducer = jmsContext.createProducer();
// Step 6. Try sending a message, we don't have the appropriate privileges to do this so this will throw an exception
jmsProducer.send(queue, "A Message from JMS2!");
System.out.println("Received:" + jmsContext.createConsumer(queue).receiveBody(String.class));
}
}
Aggregations