本文整理汇总了Java中org.springframework.jms.core.SessionCallback类的典型用法代码示例。如果您正苦于以下问题:Java SessionCallback类的具体用法?Java SessionCallback怎么用?Java SessionCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SessionCallback类属于org.springframework.jms.core包,在下文中一共展示了SessionCallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTransactionCommit
import org.springframework.jms.core.SessionCallback; //导入依赖的package包/类
@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();
}
示例2: testTransactionRollback
import org.springframework.jms.core.SessionCallback; //导入依赖的package包/类
@Test
public void testTransactionRollback() 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.rollback(ts);
verify(session).rollback();
verify(session).close();
verify(con).close();
}
示例3: checkDestination
import org.springframework.jms.core.SessionCallback; //导入依赖的package包/类
public void checkDestination(final String name, final boolean pubSub,
final boolean shouldExist) {
this.jmsTemplate.execute(new SessionCallback<Void>() {
@Override
public Void doInJms(Session session) throws JMSException {
try {
Destination destination = DestinationChecker.this.destinationResolver
.resolveDestinationName(session, name, pubSub);
if (!shouldExist) {
throw new IllegalStateException("Destination '" + name
+ "' was not expected but got " + destination);
}
}
catch (JMSException e) {
if (shouldExist) {
throw new IllegalStateException("Destination '" + name
+ "' was expected but got " + e.getMessage());
}
}
return null;
}
});
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:24,代码来源:HornetQAutoConfigurationTests.java
示例4: loadTemporaryDestinationTypes
import org.springframework.jms.core.SessionCallback; //导入依赖的package包/类
protected void loadTemporaryDestinationTypes(JmsOperations template) {
if (template == null) {
throw new IllegalArgumentException("No JmsTemplate supplied!");
}
template.execute(new SessionCallback<Object>() {
public Object doInJms(Session session) throws JMSException {
TemporaryQueue queue = session.createTemporaryQueue();
setTemporaryQueueType(queue.getClass());
TemporaryTopic topic = session.createTemporaryTopic();
setTemporaryTopicType(topic.getClass());
queue.delete();
topic.delete();
return null;
}
});
}
示例5: testTransactionCommit
import org.springframework.jms.core.SessionCallback; //导入依赖的package包/类
@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() {
@Override
public Object doInJms(Session sess) {
assertTrue(sess == session);
return null;
}
});
tm.commit(ts);
verify(session).commit();
verify(session).close();
verify(con).close();
}
示例6: testTransactionRollback
import org.springframework.jms.core.SessionCallback; //导入依赖的package包/类
@Test
public void testTransactionRollback() 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() {
@Override
public Object doInJms(Session sess) {
assertTrue(sess == session);
return null;
}
});
tm.rollback(ts);
verify(session).rollback();
verify(session).close();
verify(con).close();
}
示例7: testTransactionCommit102WithQueue
import org.springframework.jms.core.SessionCallback; //导入依赖的package包/类
@Test
@Deprecated
public void testTransactionCommit102WithQueue() throws JMSException {
QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
QueueConnection con = mock(QueueConnection.class);
final QueueSession session = mock(QueueSession.class);
given(cf.createQueueConnection()).willReturn(con);
given(con.createQueueSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session);
JmsTransactionManager tm = new JmsTransactionManager102(cf, false);
TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition());
JmsTemplate jt = new JmsTemplate102(cf, false);
jt.execute(new SessionCallback() {
@Override
public Object doInJms(Session sess) {
assertTrue(sess == session);
return null;
}
});
tm.commit(ts);
verify(session).commit();
verify(session).close();
verify(con).close();
}
示例8: testTransactionCommit102WithTopic
import org.springframework.jms.core.SessionCallback; //导入依赖的package包/类
@Test
@Deprecated
public void testTransactionCommit102WithTopic() throws JMSException {
TopicConnectionFactory cf = mock(TopicConnectionFactory.class);
TopicConnection con = mock(TopicConnection.class);
final TopicSession session = mock(TopicSession.class);
given(cf.createTopicConnection()).willReturn(con);
given(con.createTopicSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session);
JmsTransactionManager tm = new JmsTransactionManager102(cf, true);
TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition());
JmsTemplate jt = new JmsTemplate102(cf, true);
jt.execute(new SessionCallback() {
@Override
public Object doInJms(Session sess) {
assertTrue(sess == session);
return null;
}
});
tm.commit(ts);
verify(session).commit();
verify(session).close();
verify(con).close();
}
示例9: testSendRequest
import org.springframework.jms.core.SessionCallback; //导入依赖的package包/类
/**
* Tests the sending of a request to the server and receiving a response
* (decodes response and checks non null).
*
* Start a new thread to mimick the server response to a client request.
* @throws JMSException
* @throws InterruptedException
*/
@Test
public void testSendRequest() throws JMSException, InterruptedException {
JsonRequest<SupervisionEvent> jsonRequest = new ClientRequestImpl<>(SupervisionEvent.class);
final String queueName = properties.getJms().getRequestQueue() + "-" + System.currentTimeMillis();
new Thread(new Runnable() {
@Override
public void run() {
serverTemplate.execute(new SessionCallback<Object>() {
@Override
public Object doInJms(Session session) throws JMSException {
MessageConsumer consumer = session.createConsumer(new ActiveMQQueue(queueName));
Message message = consumer.receive(10000);
Assert.assertNotNull(message);
Assert.assertTrue(message instanceof TextMessage);
//send some response (empty collection)
Collection<SupervisionEvent> supervisionEvents = new ArrayList<>();
supervisionEvents.add(new SupervisionEventImpl(SupervisionEntity.PROCESS, 1L, "P_TEST", SupervisionStatus.RUNNING, new Timestamp(System.currentTimeMillis()), "test response"));
Message replyMessage = session.createTextMessage(GsonFactory.createGson().toJson(supervisionEvents));
MessageProducer producer = session.createProducer(message.getJMSReplyTo());
producer.send(replyMessage);
return null;
}
}, true);
}
}).start();
Collection<SupervisionEvent> response = jmsProxy.sendRequest(jsonRequest, queueName, 10000); //wait 10s for an answer
Assert.assertNotNull(response);
}
示例10: testConfigurationRequest
import org.springframework.jms.core.SessionCallback; //导入依赖的package包/类
/**
* Tests request is sent and response is processed. Connects to in-memory
* broker.
*/
@Test
public void testConfigurationRequest() throws Exception {
//fake DAQ responding to request
final JmsTemplate daqTemplate = new JmsTemplate(connectionFactory);
new Thread(new Runnable() {
@Override
public void run() {
try {
daqTemplate.execute(new SessionCallback<Object>() {
String reportString = MessageConverter.responseToJson(new ConfigurationChangeEventReport());
@Override
public Object doInJms(Session session) throws JMSException {
Process process = processCache.get(50L);
String jmsDaqQueue = "c2mon.process" + ".command." + process.getCurrentHost() + "." + process.getName() + "." + process.getProcessPIK();
MessageConsumer consumer = session.createConsumer(new ActiveMQQueue(jmsDaqQueue));
Message incomingMessage = consumer.receive(1000);
MessageProducer messageProducer = session.createProducer(incomingMessage.getJMSReplyTo());
TextMessage replyMessage = session.createTextMessage();
replyMessage.setText(reportString);
messageProducer.send(replyMessage);
return null;
}
}, true); //start connection
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
}).start();
//test report is picked up correctly
ConfigurationChangeEventReport report = processCommunicationManager.sendConfiguration(50L, Collections.EMPTY_LIST);
assertNotNull(report);
}
示例11: send
import org.springframework.jms.core.SessionCallback; //导入依赖的package包/类
public void send(final String destinationName,
final MessageCreator messageCreator,
final MessageSentCallback callback) throws JmsException {
execute(new SessionCallback<Object>() {
public Object doInJms(Session session) throws JMSException {
Destination destination = resolveDestinationName(session, destinationName);
return doSendToDestination(destination, messageCreator, callback, session);
}
}, false);
}
示例12: receiveBatch
import org.springframework.jms.core.SessionCallback; //导入依赖的package包/类
/**
* Receive a batch of up to batchSize for given destination. Other than batching this method is the same as {@link JmsTemplate#receive(Destination)}
* @return A list of {@link Message}
* @param destination The Destination
* @param batchSize The batch size
* @throws JmsException The {@link JmsException}
*/
public List<Message> receiveBatch(final Destination destination, final int batchSize) throws JmsException {
return execute(new SessionCallback<List<Message>>() {
public List<Message> doInJms(Session session) throws JMSException {
return doBatchReceive(session, destination, null, batchSize);
}
}, true);
}
示例13: receiveSelectedBatch
import org.springframework.jms.core.SessionCallback; //导入依赖的package包/类
/**
* Receive a batch of up to batchSize for given destination and message selector. Other than batching this method is the same as {@link JmsTemplate#receiveSelected(Destination, String)}
* @return A list of {@link Message}
* @param destination The Destination
* @param messageSelector The Selector
* @param batchSize The batch size
* @throws JmsException The {@link JmsException}
*/
public List<Message> receiveSelectedBatch(final Destination destination, final String messageSelector,
final int batchSize) throws JmsException {
return execute(new SessionCallback<List<Message>>() {
public List<Message> doInJms(Session session) throws JMSException {
return doBatchReceive(session, destination, messageSelector, batchSize);
}
}, true);
}
示例14: receive
import org.springframework.jms.core.SessionCallback; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Message receive(final Destination destination) throws JmsException {
return execute(new SessionCallback<Message>() {
public Message doInJms(Session session) throws JMSException {
return doSingleReceive(session, destination, null);
}
}, true);
}
示例15: receiveSelected
import org.springframework.jms.core.SessionCallback; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Message receiveSelected(final Destination destination, final String messageSelector) throws JmsException {
return execute(new SessionCallback<Message>() {
public Message doInJms(Session session) throws JMSException {
return doSingleReceive(session, destination, messageSelector);
}
}, true);
}