Search in sources :

Example 31 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project camel by apache.

the class AsyncConsumerFalseTest method createCamelContext.

protected CamelContext createCamelContext() throws Exception {
    CamelContext camelContext = super.createCamelContext();
    camelContext.addComponent("async", new MyAsyncComponent());
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://broker?broker.persistent=false&broker.useJmx=false");
    SjmsComponent component = new SjmsComponent();
    component.setConnectionFactory(connectionFactory);
    camelContext.addComponent("sjms", component);
    return camelContext;
}
Also used : CamelContext(org.apache.camel.CamelContext) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) MyAsyncComponent(org.apache.camel.component.sjms.support.MyAsyncComponent) SjmsComponent(org.apache.camel.component.sjms.SjmsComponent)

Example 32 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project camel by apache.

the class MyApplication method setupCamelContext.

@Override
protected void setupCamelContext(CamelContext camelContext) throws Exception {
    // setup the ActiveMQ component
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
    connectionFactory.setBrokerURL("vm://localhost?broker.persistent=false&broker.useJmx=false");
    // and register it into the CamelContext
    JmsComponent answer = new JmsComponent();
    answer.setConnectionFactory(connectionFactory);
    camelContext.addComponent("jms", answer);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) JmsComponent(org.apache.camel.component.jms.JmsComponent)

Example 33 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project adempiere by adempiere.

the class TopicExportProcessor method sendJMSMessage.

private void sendJMSMessage(String host, int port, String msg, String protocol, String topicName, String clientID, String userName, String password, int timeToLive, boolean isDeliveryModePersistent) throws JMSException {
    // Create a ConnectionFactory
    // network protocol (tcp, ...) set as EXP_ProcessorParameter
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(protocol + "://" + host + ":" + port);
    Connection connection = null;
    Session session = null;
    try {
        // Create a Connection
        if (userName != null && password != null) {
            connection = connectionFactory.createConnection(userName, password);
        } else {
            connection = connectionFactory.createConnection();
        }
        // connection.setClientID( clientID ); Commented by Victor as he had issue!
        connection.start();
        // Create a Session
        //TODO - Trifon could be EXP_ProcessorParameter
        session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
        // Create the destination (Topic or Queue)
        Destination destination = session.createTopic(topicName);
        // Create a MessageProducer from the Session to the Topic or Queue
        MessageProducer producer = session.createProducer(destination);
        // EXP_ProcessorParameter
        producer.setTimeToLive(timeToLive);
        if (isDeliveryModePersistent) {
            // EXP_ProcessorParameter	
            producer.setDeliveryMode(DeliveryMode.PERSISTENT);
        } else {
            // EXP_ProcessorParameter
            producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        }
        // How to send to multiple destinations.
        //MessageProducer producer = session.createProducer(null);
        //producer.send(someDestination, message);
        //producer.send(anotherDestination, message);
        // Create a message
        TextMessage message = session.createTextMessage(msg);
        // Tell the producer to send the message
        try {
            producer.send(message);
            session.commit();
            log.info("JMS Message sent!");
        } catch (JMSException ex) {
            session.rollback();
            log.info("JMS Can't send the message!");
            throw ex;
        }
    } finally {
        // Clean up
        if (session != null) {
            try {
                session.close();
            } catch (JMSException ex) {
            /* ignored */
            }
        }
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException ex) {
            /* ignored */
            }
        }
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Destination(javax.jms.Destination) Connection(javax.jms.Connection) JMSException(javax.jms.JMSException) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Example 34 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project adempiere by adempiere.

the class TopicListener method run.

public void run() throws JMSException {
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url);
    log.finest("ActiveMQConnectionFactory = " + factory);
    if (userName != null && password != null) {
        conn = factory.createConnection(userName, password);
    } else {
        conn = factory.createConnection();
    }
    log.finest("conn = " + conn);
    if (conn.getClientID() == null) {
        try {
            conn.setClientID(clientID);
        } catch (Exception e) {
            //log.info("Connection with clientID '" + clientID +"' already exists" + e.toString());
            conn.close();
            return;
        }
    } else {
        if (conn.getClientID().equals(clientID)) {
            log.warning("Connection with clientID '" + clientID + "' already exists");
            conn.close();
            return;
        } else {
            try {
                conn.setClientID(clientID);
            } catch (Exception e) {
                log.info("Error while invoking setClientID(" + clientID + ")! " + e.getMessage());
                conn.close();
                return;
            }
        }
    }
    // TODO - could be parameter
    session = conn.createSession(true, Session.AUTO_ACKNOWLEDGE);
    log.finest("session = " + session);
    log.finest("topicName = " + topicName);
    log.finest("subscriptionName = " + subscriptionName);
    topic = session.createTopic(topicName);
    log.finest("topic = " + topic);
    MessageConsumer consumer = null;
    if (isDurableSubscription) {
        // http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.pmc.express.doc/tasks/tjn0012_.html
        // The subscriptionName assigned to a durable subscription must be unique within a given client ID.
        consumer = session.createDurableSubscriber(topic, subscriptionName);
    } else {
        consumer = session.createConsumer(topic);
    }
    log.finest("consumer = " + consumer);
    consumer.setMessageListener(this);
    conn.start();
    log.finest("Waiting for JMS messages...");
    if (replicationProcessor != null) {
        MIMPProcessorLog pLog = new MIMPProcessorLog(replicationProcessor.getMImportProcessor(), "Connected to JMS Server. Waiting for messages!");
        StringBuffer logReference = new StringBuffer("topicName = ").append(topicName).append(", subscriptionName = ").append(subscriptionName);
        pLog.setReference(logReference.toString());
        boolean resultSave = pLog.save();
        log.finest("Result Save = " + resultSave);
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) MIMPProcessorLog(org.compiere.model.MIMPProcessorLog) JMSException(javax.jms.JMSException)

Example 35 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project beam by apache.

the class JmsIOTest method startBroker.

@Before
public void startBroker() throws Exception {
    broker = new BrokerService();
    broker.setUseJmx(false);
    broker.setPersistenceAdapter(new MemoryPersistenceAdapter());
    broker.addConnector(BROKER_URL);
    broker.setBrokerName("localhost");
    broker.setPopulateJMSXUserID(true);
    broker.setUseAuthenticatedPrincipalForJMSXUserID(true);
    // enable authentication
    List<AuthenticationUser> users = new ArrayList<>();
    // username and password to use to connect to the broker.
    // This user has users privilege (able to browse, consume, produce, list destinations)
    users.add(new AuthenticationUser(USERNAME, PASSWORD, "users"));
    SimpleAuthenticationPlugin plugin = new SimpleAuthenticationPlugin(users);
    BrokerPlugin[] plugins = new BrokerPlugin[] { plugin };
    broker.setPlugins(plugins);
    broker.start();
    // create JMS connection factory
    connectionFactory = new ActiveMQConnectionFactory(BROKER_URL);
    connectionFactoryWithoutPrefetch = new ActiveMQConnectionFactory(BROKER_URL + "?jms.prefetchPolicy.all=0");
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) MemoryPersistenceAdapter(org.apache.activemq.store.memory.MemoryPersistenceAdapter) SimpleAuthenticationPlugin(org.apache.activemq.security.SimpleAuthenticationPlugin) ArrayList(java.util.ArrayList) BrokerPlugin(org.apache.activemq.broker.BrokerPlugin) BrokerService(org.apache.activemq.broker.BrokerService) AuthenticationUser(org.apache.activemq.security.AuthenticationUser) Before(org.junit.Before)

Aggregations

ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)69 CamelContext (org.apache.camel.CamelContext)25 SjmsComponent (org.apache.camel.component.sjms.SjmsComponent)16 ConnectionFactory (javax.jms.ConnectionFactory)11 Test (org.junit.Test)10 PooledConnectionFactory (org.apache.activemq.pool.PooledConnectionFactory)9 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)8 JmsTemplate (org.springframework.jms.core.JmsTemplate)7 Connection (javax.jms.Connection)6 Session (javax.jms.Session)6 Before (org.junit.Before)5 MessageProducer (javax.jms.MessageProducer)4 RouteBuilder (org.apache.camel.builder.RouteBuilder)4 SimpleRegistry (org.apache.camel.impl.SimpleRegistry)4 File (java.io.File)3 Destination (javax.jms.Destination)3 JMSException (javax.jms.JMSException)3 MessageConsumer (javax.jms.MessageConsumer)3 BrokerService (org.apache.activemq.broker.BrokerService)3 ArrayList (java.util.ArrayList)2