use of javax.jms.TopicConnection in project spring-framework by spring-projects.
the class SingleConnectionFactoryTests method testWithTopicConnectionFactoryAndJms11Usage.
@Test
public void testWithTopicConnectionFactoryAndJms11Usage() throws JMSException {
TopicConnectionFactory cf = mock(TopicConnectionFactory.class);
TopicConnection con = mock(TopicConnection.class);
given(cf.createConnection()).willReturn(con);
SingleConnectionFactory scf = new SingleConnectionFactory(cf);
Connection con1 = scf.createConnection();
Connection con2 = scf.createConnection();
con1.start();
con2.start();
con1.close();
con2.close();
// should trigger actual close
scf.destroy();
verify(con).start();
verify(con).stop();
verify(con).close();
verifyNoMoreInteractions(con);
}
use of javax.jms.TopicConnection in project spring-framework by spring-projects.
the class SingleConnectionFactoryTests method testCachingConnectionFactoryWithTopicConnectionFactoryAndJms102Usage.
@Test
public void testCachingConnectionFactoryWithTopicConnectionFactoryAndJms102Usage() throws JMSException {
TopicConnectionFactory cf = mock(TopicConnectionFactory.class);
TopicConnection con = mock(TopicConnection.class);
TopicSession txSession = mock(TopicSession.class);
TopicSession nonTxSession = mock(TopicSession.class);
given(cf.createTopicConnection()).willReturn(con);
given(con.createTopicSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(txSession);
given(txSession.getTransacted()).willReturn(true);
given(con.createTopicSession(false, Session.CLIENT_ACKNOWLEDGE)).willReturn(nonTxSession);
CachingConnectionFactory scf = new CachingConnectionFactory(cf);
scf.setReconnectOnException(false);
Connection con1 = scf.createTopicConnection();
Session session1 = con1.createSession(true, Session.AUTO_ACKNOWLEDGE);
session1.getTransacted();
// should lead to rollback
session1.close();
session1 = con1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
session1.close();
con1.start();
TopicConnection con2 = scf.createTopicConnection();
Session session2 = con2.createTopicSession(false, Session.CLIENT_ACKNOWLEDGE);
session2.close();
session2 = con2.createSession(true, Session.AUTO_ACKNOWLEDGE);
session2.getTransacted();
session2.close();
con2.start();
con1.close();
con2.close();
// should trigger actual close
scf.destroy();
verify(txSession).close();
verify(nonTxSession).close();
verify(con).start();
verify(con).stop();
verify(con).close();
}
use of javax.jms.TopicConnection in project carbon-apimgt by wso2.
the class BrokerUtil method publishToTopic.
/**
* Publish to broker topic
*
* @param topicName publishing topic name
* @param gatewayEvent topic message data object
*/
public static void publishToTopic(String topicName, GatewayEvent gatewayEvent) throws GatewayException {
TopicSession topicSession = null;
Topic topic = null;
TopicPublisher topicPublisher = null;
TopicConnection topicConnection = null;
try {
topicConnection = getTopicConnection();
topicConnection.start();
topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
topic = topicSession.createTopic(topicName);
topicPublisher = topicSession.createPublisher(topic);
TextMessage textMessage = topicSession.createTextMessage(new Gson().toJson(gatewayEvent));
topicPublisher.publish(textMessage);
} catch (JMSException e) {
String errorMessage = "Error occurred while publishing " + gatewayEvent.getEventType() + " event to JMS " + "topic :" + topicName;
log.error(errorMessage, e);
throw new GatewayException(errorMessage, ExceptionCodes.GATEWAY_EXCEPTION);
} catch (BrokerException e) {
String errorMessage = "Error occurred while obtaining broker topic connection for topic : " + topicName;
log.error(errorMessage, e);
throw new GatewayException(errorMessage, ExceptionCodes.GATEWAY_EXCEPTION);
} finally {
if (topicPublisher != null) {
try {
topicPublisher.close();
} catch (JMSException e) {
log.error("Error occurred while closing topic publisher for topic : " + topicName);
}
}
if (topicSession != null) {
try {
topicSession.close();
} catch (JMSException e) {
log.error("Error occurred while closing topic session for topic : " + topicName);
}
}
if (topicConnection != null) {
try {
topicConnection.close();
} catch (JMSException e) {
log.error("Error occurred while closing topic connection for topic : " + topicName);
}
}
}
}
use of javax.jms.TopicConnection in project spring-framework by spring-projects.
the class SingleConnectionFactoryTests method testWithTopicConnectionFactoryAndJms102Usage.
@Test
public void testWithTopicConnectionFactoryAndJms102Usage() throws JMSException {
TopicConnectionFactory cf = mock(TopicConnectionFactory.class);
TopicConnection con = mock(TopicConnection.class);
given(cf.createTopicConnection()).willReturn(con);
SingleConnectionFactory scf = new SingleConnectionFactory(cf);
Connection con1 = scf.createTopicConnection();
Connection con2 = scf.createTopicConnection();
con1.start();
con2.start();
con1.close();
con2.close();
// should trigger actual close
scf.destroy();
verify(con).start();
verify(con).stop();
verify(con).close();
verifyNoMoreInteractions(con);
}
use of javax.jms.TopicConnection in project spring-framework by spring-projects.
the class SingleConnectionFactoryTests method testWithTopicConnection.
@Test
public void testWithTopicConnection() throws JMSException {
Connection con = mock(TopicConnection.class);
SingleConnectionFactory scf = new SingleConnectionFactory(con);
TopicConnection con1 = scf.createTopicConnection();
con1.start();
con1.stop();
con1.close();
TopicConnection con2 = scf.createTopicConnection();
con2.start();
con2.stop();
con2.close();
// should trigger actual close
scf.destroy();
verify(con, times(2)).start();
verify(con, times(2)).stop();
verify(con).close();
verifyNoMoreInteractions(con);
}
Aggregations