Search in sources :

Example 1 with JmsConnection

use of com.adaptris.core.jms.JmsConnection in project interlok by adaptris.

the class BlobMessageTranslatorTest method testMoveMetadataAdaptrisMessageToJmsMessage.

@Test
public void testMoveMetadataAdaptrisMessageToJmsMessage() throws Exception {
    MessageTypeTranslatorImp trans = new BlobMessageTranslator();
    JmsConnection conn = null;
    try {
        conn = activeMqBroker.getJmsConnection(new BasicActiveMqImplementation());
        start(conn);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        addMetadata(msg);
        Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        trans.registerSession(session);
        trans.registerMessageFactory(new DefaultMessageFactory());
        start(trans);
        Message jmsMsg = trans.translate(msg);
        assertJmsProperties(jmsMsg);
    } finally {
        stop(trans);
        stop(conn);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Message(javax.jms.Message) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MessageTypeTranslatorImp(com.adaptris.core.jms.MessageTypeTranslatorImp) JmsConnection(com.adaptris.core.jms.JmsConnection) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.ActiveMQSession) Test(org.junit.Test)

Example 2 with JmsConnection

use of com.adaptris.core.jms.JmsConnection in project interlok by adaptris.

the class BlobMessageTranslatorTest method testMoveJmsHeadersJmsMessageToAdaptrisMessage.

@Test
public void testMoveJmsHeadersJmsMessageToAdaptrisMessage() throws Exception {
    MessageTypeTranslatorImp trans = new BlobMessageTranslator();
    JmsConnection conn = null;
    try {
        conn = activeMqBroker.getJmsConnection(new BasicActiveMqImplementation());
        start(conn);
        Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        Message jmsMsg = createMessage(session);
        jmsMsg.setJMSCorrelationID("ABC");
        jmsMsg.setJMSDeliveryMode(1);
        jmsMsg.setJMSPriority(4);
        addProperties(jmsMsg);
        long timestamp = System.currentTimeMillis();
        jmsMsg.setJMSTimestamp(timestamp);
        trans.registerSession(session);
        trans.registerMessageFactory(new DefaultMessageFactory());
        trans.setMoveJmsHeaders(true);
        start(trans);
        AdaptrisMessage msg = trans.translate(jmsMsg);
        assertMetadata(msg);
        assertEquals("ABC", msg.getMetadataValue(JmsConstants.JMS_CORRELATION_ID));
        assertEquals("1", msg.getMetadataValue(JmsConstants.JMS_DELIVERY_MODE));
        assertEquals("4", msg.getMetadataValue(JmsConstants.JMS_PRIORITY));
        assertEquals(String.valueOf(timestamp), msg.getMetadataValue(JmsConstants.JMS_TIMESTAMP));
    } finally {
        stop(trans);
        stop(conn);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Message(javax.jms.Message) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MessageTypeTranslatorImp(com.adaptris.core.jms.MessageTypeTranslatorImp) JmsConnection(com.adaptris.core.jms.JmsConnection) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.ActiveMQSession) Test(org.junit.Test)

Example 3 with JmsConnection

use of com.adaptris.core.jms.JmsConnection in project interlok by adaptris.

the class EmbeddedActiveMq method getFailoverJmsConnection.

public FailoverJmsConnection getFailoverJmsConnection(boolean isPtp) throws Exception {
    FailoverJmsConnection result = new FailoverJmsConnection();
    if (!isPtp) {
        JmsConnection c = new JmsConnection(new BasicActiveMqImplementation(DEF_URL_PREFIX + "9999"));
        result.addConnection(c);
        result.addConnection(getJmsConnection(new BasicActiveMqImplementation(), true));
    } else {
        JmsConnection c = new JmsConnection(new BasicActiveMqImplementation(DEF_URL_PREFIX + "9999"));
        result.addConnection(c);
        result.addConnection(getJmsConnection(new BasicActiveMqImplementation(), true));
    }
    return result;
}
Also used : FailoverJmsConnection(com.adaptris.core.jms.FailoverJmsConnection) JmsConnection(com.adaptris.core.jms.JmsConnection) FailoverJmsConnection(com.adaptris.core.jms.FailoverJmsConnection)

Example 4 with JmsConnection

use of com.adaptris.core.jms.JmsConnection in project interlok by adaptris.

the class ActiveMqPasPollingConsumerTest method createStandalone.

private StandaloneConsumer createStandalone(EmbeddedActiveMq mq, String threadName, String destinationName) throws Exception {
    PasPollingConsumer consumer = new PasPollingConsumer().withTopic(destinationName);
    consumer.setPoller(new Sometime());
    JmsConnection c = mq.getJmsConnection();
    consumer.setVendorImplementation(c.getVendorImplementation());
    consumer.setClientId(c.getClientId());
    consumer.setSubscriptionId(MY_SUBSCRIPTION_ID);
    consumer.setReacquireLockBetweenMessages(true);
    consumer.setAdditionalDebug(true);
    consumer.setReceiveTimeout(new TimeInterval(Integer.valueOf(new Random().nextInt(100) + 100).longValue(), TimeUnit.MILLISECONDS));
    StandaloneConsumer sc = new StandaloneConsumer(consumer);
    return sc;
}
Also used : PasPollingConsumer(com.adaptris.core.jms.PasPollingConsumer) TimeInterval(com.adaptris.util.TimeInterval) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) JmsConnection(com.adaptris.core.jms.JmsConnection) StandaloneConsumer(com.adaptris.core.StandaloneConsumer)

Example 5 with JmsConnection

use of com.adaptris.core.jms.JmsConnection in project interlok by adaptris.

the class AdvancedActiveMqConsumerTest method retrieveObjectForSampleConfig.

@Override
protected Object retrieveObjectForSampleConfig() {
    JmsConnection connection = new JmsConnection();
    PtpConsumer producer = new PtpConsumer();
    producer.setQueue("destination");
    UrlVendorImplementation vendorImpl = createImpl();
    vendorImpl.setBrokerUrl(BasicActiveMqImplementationTest.PRIMARY);
    connection.setUserName("BrokerUsername");
    connection.setPassword("BrokerPassword");
    connection.setVendorImplementation(vendorImpl);
    StandaloneConsumer result = new StandaloneConsumer();
    result.setConnection(connection);
    result.setConsumer(producer);
    return result;
}
Also used : PtpConsumer(com.adaptris.core.jms.PtpConsumer) UrlVendorImplementation(com.adaptris.core.jms.UrlVendorImplementation) JmsConnection(com.adaptris.core.jms.JmsConnection) StandaloneConsumer(com.adaptris.core.StandaloneConsumer)

Aggregations

JmsConnection (com.adaptris.core.jms.JmsConnection)47 Test (org.junit.Test)25 StandaloneProducer (com.adaptris.core.StandaloneProducer)17 StandardJndiImplementation (com.adaptris.core.jms.jndi.StandardJndiImplementation)14 TimeInterval (com.adaptris.util.TimeInterval)14 PasProducer (com.adaptris.core.jms.PasProducer)12 MockChannel (com.adaptris.core.stubs.MockChannel)10 StandaloneConsumer (com.adaptris.core.StandaloneConsumer)8 PtpProducer (com.adaptris.core.jms.PtpProducer)8 KeyValuePair (com.adaptris.util.KeyValuePair)6 Adapter (com.adaptris.core.Adapter)5 PtpConsumer (com.adaptris.core.jms.PtpConsumer)5 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)5 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)4 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)4 SharedConnection (com.adaptris.core.SharedConnection)4 MessageTypeTranslatorImp (com.adaptris.core.jms.MessageTypeTranslatorImp)4 UrlVendorImplementation (com.adaptris.core.jms.UrlVendorImplementation)4 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)4 Message (javax.jms.Message)4