use of com.adaptris.core.jms.JmsConnection in project interlok by adaptris.
the class AdvancedActiveMqProducerTest method retrieveObjectForSampleConfig.
@Override
protected Object retrieveObjectForSampleConfig() {
JmsConnection connection = new JmsConnection();
PtpProducer producer = new PtpProducer();
producer.setQueue("destination");
UrlVendorImplementation vendorImpl = createImpl();
vendorImpl.setBrokerUrl(BasicActiveMqImplementationTest.PRIMARY);
connection.setUserName("BrokerUsername");
connection.setPassword("BrokerPassword");
connection.setVendorImplementation(vendorImpl);
StandaloneProducer result = new StandaloneProducer();
result.setConnection(connection);
result.setProducer(producer);
return result;
}
use of com.adaptris.core.jms.JmsConnection in project interlok by adaptris.
the class BasicActiveMqConsumerTest method createDurableSubsAdapter.
private Adapter createDurableSubsAdapter(String adapterName, EmbeddedActiveMq activeMqBroker) throws Exception {
Adapter adapter = new Adapter();
adapter.setUniqueId(adapterName);
Channel c = new Channel();
JmsConnection conn = activeMqBroker.getJmsConnection(createVendorImpl());
conn.setClientId(MY_CLIENT_ID);
c.setConsumeConnection(conn);
StandardWorkflow swf = new StandardWorkflow();
PasConsumer pasConsumer = new PasConsumer().withTopic(new GuidGenerator().safeUUID());
pasConsumer.setSubscriptionId(MY_SUBSCRIPTION_ID);
swf.setConsumer(pasConsumer);
c.getWorkflowList().add(swf);
ChannelList cl = new ChannelList();
cl.addChannel(c);
adapter.setChannelList(cl);
return adapter;
}
use of com.adaptris.core.jms.JmsConnection in project interlok by adaptris.
the class ActiveJmsConnectionErrorHandlerTest method testActiveRestartSharedConnection.
@Test
public void testActiveRestartSharedConnection() throws Exception {
Adapter adapter = new Adapter();
adapter.setUniqueId(testName.getMethodName());
JmsConnection connection = activeMqBroker.getJmsConnection(new BasicActiveMqImplementation(), true);
connection.setConnectionErrorHandler(createErrorHandler());
connection.setUniqueId(testName.getMethodName());
connection.setConnectionRetryInterval(new TimeInterval(5L, "SECONDS"));
connection.setConnectionAttempts(null);
adapter.getSharedComponents().addConnection(connection);
MockChannel channel = createChannel(activeMqBroker, new SharedConnection(testName.getMethodName()), testName.getMethodName());
MockMessageProducer producer = (MockMessageProducer) channel.getWorkflowList().get(0).getProducer();
adapter.getChannelList().add(channel);
try {
adapter.requestStart();
assertEquals(StartedState.getInstance(), channel.retrieveComponentState());
// Now try and send a message
ExampleServiceCase.execute(createProducer(activeMqBroker, testName.getMethodName()), AdaptrisMessageFactory.getDefaultInstance().newMessage("ABC"));
waitForMessages(producer, 1);
activeMqBroker.stop();
log.trace(testName.getMethodName() + ": Waiting for channel death (i.e. !StartedState)");
long totalWaitTime = waitForChannelToChangeState(StartedState.getInstance(), channel);
log.trace(testName.getMethodName() + ": Channel appears to be not started now, and I waited for " + totalWaitTime);
activeMqBroker.start();
totalWaitTime = waitForChannelToMatchState(StartedState.getInstance(), channel);
log.trace(testName.getMethodName() + ": Channel now started now, and I waited for " + totalWaitTime);
assertEquals(StartedState.getInstance(), channel.retrieveComponentState());
// Now try and send a message
ExampleServiceCase.execute(createProducer(activeMqBroker, testName.getMethodName()), AdaptrisMessageFactory.getDefaultInstance().newMessage("ABC"));
waitForMessages(producer, 2);
} finally {
adapter.requestClose();
}
}
use of com.adaptris.core.jms.JmsConnection in project interlok by adaptris.
the class ActiveJmsConnectionErrorHandlerTest method testConnectionErrorHandlerWhileConnectionIsClosed.
@Test
public void testConnectionErrorHandlerWhileConnectionIsClosed() throws Exception {
String queueName = testName.getMethodName() + "_queue";
String topicName = testName.getMethodName() + "_topic";
JmsConnection jmsCon = activeMqBroker.getJndiPasConnection(new StandardJndiImplementation(), false, queueName, topicName);
jmsCon.setConnectionAttempts(null);
MockChannel channel = createChannel(activeMqBroker, jmsCon, topicName);
try {
ActiveJmsConnectionErrorHandler handler = new ActiveJmsConnectionErrorHandler();
handler.setCheckInterval(new TimeInterval(100L, TimeUnit.MILLISECONDS));
handler.setAdditionalLogging(Boolean.TRUE);
channel.getConsumeConnection().setConnectionErrorHandler(handler);
channel.requestStart();
assertEquals(StartedState.getInstance(), channel.retrieveComponentState());
channel.requestClose();
activeMqBroker.stop();
activeMqBroker.start();
assertEquals(ClosedState.getInstance(), channel.retrieveComponentState());
} finally {
channel.requestClose();
}
}
use of com.adaptris.core.jms.JmsConnection in project interlok by adaptris.
the class BasicActiveMqProducerTest method testTopicProduceAndConsume_DurableSubscriber_Legacy.
@Test
public void testTopicProduceAndConsume_DurableSubscriber_Legacy() throws Exception {
String subscriptionId = GUID.safeUUID();
String clientId = GUID.safeUUID();
PasConsumer consumer = new PasConsumer().withTopic(getName());
consumer.setSubscriptionId(subscriptionId);
consumer.setAcknowledgeMode("AUTO_ACKNOWLEDGE");
JmsConnection conn = activeMqBroker.getJmsConnection(createVendorImpl(), true);
conn.setClientId(clientId);
StandaloneConsumer standaloneConsumer = new StandaloneConsumer(conn, consumer);
MockMessageListener jms = new MockMessageListener();
standaloneConsumer.registerAdaptrisMessageListener(jms);
// Start it once to get some durable Action.
start(standaloneConsumer);
stop(standaloneConsumer);
StandaloneProducer standaloneProducer = new StandaloneProducer(activeMqBroker.getJmsConnection(createVendorImpl()), new PasProducer().withTopic(getName()));
int count = 10;
for (int i = 0; i < count; i++) {
ExampleServiceCase.execute(standaloneProducer, createMessage());
}
start(standaloneConsumer);
waitForMessages(jms, count);
assertMessages(jms, 10);
}
Aggregations