use of org.springframework.jms.core.JmsTemplate in project camel by apache.
the class JmsRequestReplyManualReplyTest method createCamelContext.
protected CamelContext createCamelContext() throws Exception {
CamelContext camelContext = super.createCamelContext();
ConnectionFactory connectionFactory = CamelJmsTestHelper.createConnectionFactory();
camelContext.addComponent("activemq", jmsComponentAutoAcknowledge(connectionFactory));
jms = new JmsTemplate(connectionFactory);
return camelContext;
}
use of org.springframework.jms.core.JmsTemplate in project camel by apache.
the class JmsCustomJMSReplyToIssueTest method testCustomJMSReplyTo.
@Test
public void testCustomJMSReplyTo() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Bye World");
// start a inOnly route
template.sendBody("direct:start", "Hello World");
// now consume using something that is not Camel
Thread.sleep(1000);
JmsTemplate jms = new JmsTemplate(amq.getConfiguration().getConnectionFactory());
TextMessage msg = (TextMessage) jms.receive("in");
assertEquals("Hello World", msg.getText());
// there should be a JMSReplyTo so we know where to send the reply
Destination replyTo = msg.getJMSReplyTo();
assertEquals("queue://myReplyQueue", replyTo.toString());
// send reply
template.sendBody("activemq:" + replyTo.toString(), "Bye World");
assertMockEndpointsSatisfied();
}
use of org.springframework.jms.core.JmsTemplate in project spring-framework by spring-projects.
the class JmsTransactionManagerTests method testTransactionCommit.
@Test
public void testTransactionCommit() throws JMSException {
ConnectionFactory cf = mock(ConnectionFactory.class);
Connection con = mock(Connection.class);
final Session session = mock(Session.class);
given(cf.createConnection()).willReturn(con);
given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session);
JmsTransactionManager tm = new JmsTransactionManager(cf);
TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition());
JmsTemplate jt = new JmsTemplate(cf);
jt.execute(new SessionCallback<Void>() {
@Override
public Void doInJms(Session sess) {
assertTrue(sess == session);
return null;
}
});
tm.commit(ts);
verify(session).commit();
verify(session).close();
verify(con).close();
}
use of org.springframework.jms.core.JmsTemplate in project spring-framework by spring-projects.
the class JmsTransactionManagerTests method testTransactionSuspension.
@Test
public void testTransactionSuspension() throws JMSException {
final ConnectionFactory cf = mock(ConnectionFactory.class);
Connection con = mock(Connection.class);
final Session session = mock(Session.class);
final Session session2 = mock(Session.class);
given(cf.createConnection()).willReturn(con);
given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session, session2);
JmsTransactionManager tm = new JmsTransactionManager(cf);
TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition());
final JmsTemplate jt = new JmsTemplate(cf);
jt.execute(new SessionCallback<Void>() {
@Override
public Void doInJms(Session sess) {
assertTrue(sess == session);
return null;
}
});
TransactionTemplate tt = new TransactionTemplate(tm);
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
jt.execute(new SessionCallback<Void>() {
@Override
public Void doInJms(Session sess) {
assertTrue(sess != session);
return null;
}
});
}
});
jt.execute(new SessionCallback<Void>() {
@Override
public Void doInJms(Session sess) {
assertTrue(sess == session);
return null;
}
});
tm.commit(ts);
verify(session).commit();
verify(session2).commit();
verify(session).close();
verify(session2).close();
verify(con, times(2)).close();
}
use of org.springframework.jms.core.JmsTemplate in project spring-framework by spring-projects.
the class JmsTransactionManagerTests method testParticipatingTransactionWithCommit.
@Test
public void testParticipatingTransactionWithCommit() throws JMSException {
ConnectionFactory cf = mock(ConnectionFactory.class);
Connection con = mock(Connection.class);
final Session session = mock(Session.class);
given(cf.createConnection()).willReturn(con);
given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session);
JmsTransactionManager tm = new JmsTransactionManager(cf);
TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition());
final JmsTemplate jt = new JmsTemplate(cf);
jt.execute(new SessionCallback<Void>() {
@Override
public Void doInJms(Session sess) {
assertTrue(sess == session);
return null;
}
});
TransactionTemplate tt = new TransactionTemplate(tm);
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
jt.execute(new SessionCallback<Void>() {
@Override
public Void doInJms(Session sess) {
assertTrue(sess == session);
return null;
}
});
}
});
tm.commit(ts);
verify(session).commit();
verify(session).close();
verify(con).close();
}
Aggregations