use of com.adaptris.core.StandaloneConsumer in project interlok by adaptris.
the class JmsProducerTest method testDefaultSessionFactory.
@Test
public void testDefaultSessionFactory() throws Exception {
String rfc6167 = "jms:queue:" + getName() + "";
JmsConsumerImpl consumer = createConsumer(getName());
consumer.setAcknowledgeMode("AUTO_ACKNOWLEDGE");
StandaloneConsumer standaloneConsumer = new StandaloneConsumer(activeMqBroker.getJmsConnection(), consumer);
MockMessageListener jms = new MockMessageListener();
JmsProducer producer = createProducer(rfc6167);
producer.setSessionFactory(new DefaultProducerSessionFactory());
StandaloneProducer sp = new StandaloneProducer(activeMqBroker.getJmsConnection(), producer);
standaloneConsumer.registerAdaptrisMessageListener(jms);
try {
start(standaloneConsumer, sp);
sp.doService(createMessage());
sp.doService(createMessage());
waitForMessages(jms, 2);
assertMessages(jms, 2);
} finally {
stop(sp, standaloneConsumer);
}
}
use of com.adaptris.core.StandaloneConsumer in project interlok by adaptris.
the class JmsSyncConsumerTest method testDeferConsumerCreationToVendor.
@Test
public void testDeferConsumerCreationToVendor() throws Exception {
Assume.assumeTrue(JmsConfig.jmsTestsEnabled());
when(mockVendor.createConsumer(any(), any(), any(JmsActorConfig.class))).thenReturn(mockMessageConsumer);
when(mockVendor.getBrokerUrl()).thenReturn("vm://" + activeMqBroker.getName());
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://" + activeMqBroker.getName());
when(mockVendor.createConnectionFactory()).thenReturn(factory);
when(mockVendor.createConnection(any(), any())).thenReturn(factory.createConnection());
JmsConnection jmsConnection = activeMqBroker.getJmsConnection();
jmsConnection.setVendorImplementation(mockVendor);
StandaloneConsumer standaloneConsumer = createStandaloneConsumer(jmsConnection, false, true);
MockMessageListener jms = new MockMessageListener();
standaloneConsumer.registerAdaptrisMessageListener(jms);
LifecycleHelper.initAndStart(standaloneConsumer);
verify(mockVendor).createConsumer(any(), any(), any(JmsSyncConsumer.class));
LifecycleHelper.stopAndClose(standaloneConsumer);
}
use of com.adaptris.core.StandaloneConsumer in project interlok by adaptris.
the class FailoverJmsProducerCase method testEventuallyConnects.
@Test
public void testEventuallyConnects() throws Exception {
FailoverJmsConnection connection = new FailoverJmsConnection();
connection.addConnection(new JmsConnection(new BasicActiveMqImplementation("tcp://localhost:123456")));
connection.addConnection(activeMqBroker.getJmsConnection(new BasicActiveMqImplementation(), true));
connection.setConnectionRetryInterval(new TimeInterval(250L, TimeUnit.MILLISECONDS));
connection.addExceptionListener(new StandaloneConsumer());
connection.setRegisterOwner(true);
ScheduledExecutorService es = Executors.newSingleThreadScheduledExecutor();
try {
es.schedule(new Runnable() {
@Override
public void run() {
try {
activeMqBroker.start();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}, 2L, TimeUnit.SECONDS);
LifecycleHelper.initAndStart(connection);
} finally {
LifecycleHelper.stopAndClose(connection);
es.shutdownNow();
}
}
use of com.adaptris.core.StandaloneConsumer in project interlok by adaptris.
the class BasicJmsProducerCase method testPerMessageSession.
@Test
public void testPerMessageSession() throws Exception {
JmsConsumerImpl consumer = createConsumer(getName());
consumer.setAcknowledgeMode("AUTO_ACKNOWLEDGE");
StandaloneConsumer standaloneConsumer = new StandaloneConsumer(activeMqBroker.getJmsConnection(), consumer);
MockMessageListener jms = new MockMessageListener();
standaloneConsumer.registerAdaptrisMessageListener(jms);
DefinedJmsProducer producer = createProducer(getName());
producer.setSessionFactory(new PerMessageProducerSessionFactory());
StandaloneProducer standaloneProducer = new StandaloneProducer(activeMqBroker.getJmsConnection(), producer);
try {
start(standaloneConsumer, standaloneProducer);
standaloneProducer.doService(createMessage());
// Should create a new Session now.
standaloneProducer.doService(createMessage());
waitForMessages(jms, 2);
assertMessages(jms, 2);
} finally {
stop(standaloneProducer, standaloneConsumer);
}
}
use of com.adaptris.core.StandaloneConsumer in project interlok by adaptris.
the class BasicJmsProducerCase method testMessageCountSession.
@Test
public void testMessageCountSession() throws Exception {
JmsConsumerImpl consumer = createConsumer(getName());
consumer.setAcknowledgeMode("AUTO_ACKNOWLEDGE");
StandaloneConsumer standaloneConsumer = new StandaloneConsumer(activeMqBroker.getJmsConnection(), consumer);
MockMessageListener jms = new MockMessageListener();
DefinedJmsProducer producer = createProducer(getName());
MessageCountProducerSessionFactory psf = new MessageCountProducerSessionFactory(1);
producer.setSessionFactory(psf);
standaloneConsumer.registerAdaptrisMessageListener(jms);
StandaloneProducer standaloneProducer = new StandaloneProducer(activeMqBroker.getJmsConnection(), producer);
try {
start(standaloneConsumer, standaloneProducer);
standaloneProducer.doService(createMessage());
standaloneProducer.doService(createMessage());
assertTrue(psf.newSessionRequired());
// Should create a new Session now.
standaloneProducer.doService(createMessage());
waitForMessages(jms, 3);
assertMessages(jms, 3);
} finally {
stop(standaloneProducer, standaloneConsumer);
}
}
Aggregations