Search in sources :

Example 1 with ActiveMQConnectionFactory

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

the class TestMsgBusConnection method connectClient.

private void connectClient() throws JMSException {
    ConnectionFactory connFac = new ActiveMQConnectionFactory("tcp://localhost:61616");
    Connection conn = connFac.createConnection();
    conn.start();
    Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
    Destination hcatTopic = session.createTopic("planetlab.hcat");
    consumer = session.createConsumer(hcatTopic);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Destination(javax.jms.Destination) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) Connection(javax.jms.Connection) Session(javax.jms.Session)

Example 2 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project pinpoint by naver.

the class TestBroker method start.

boolean start() throws Exception {
    this.brokerService.start();
    // but this method was only introduced in 5.3.0
    for (Map.Entry<String, ActiveMQConnectionFactory> e : this.connectionFactories.entrySet()) {
        String connectUri = e.getKey();
        ActiveMQConnectionFactory connectionFactory = e.getValue();
        ActiveMQConnection connection = (ActiveMQConnection) connectionFactory.createConnection();
        connection.setClientID("client_" + connectUri);
        connection.start();
        this.connections.put(connectUri, connection);
    }
    return true;
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ActiveMQConnection(org.apache.activemq.ActiveMQConnection) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 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 4 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 5 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project spring-boot by spring-projects.

the class ActiveMQAutoConfigurationTests method brokerIsEmbeddedByDefault.

@Test
public void brokerIsEmbeddedByDefault() {
    load(EmptyConfiguration.class);
    ConnectionFactory connectionFactory = this.context.getBean(ConnectionFactory.class);
    assertThat(connectionFactory).isInstanceOf(ActiveMQConnectionFactory.class);
    String brokerUrl = ((ActiveMQConnectionFactory) connectionFactory).getBrokerURL();
    assertThat(brokerUrl).isEqualTo("vm://localhost?broker.persistent=false");
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) PooledConnectionFactory(org.apache.activemq.pool.PooledConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) Test(org.junit.Test)

Aggregations

ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)434 Session (javax.jms.Session)148 Connection (javax.jms.Connection)144 Test (org.junit.Test)107 MessageConsumer (javax.jms.MessageConsumer)103 TextMessage (javax.jms.TextMessage)81 MessageProducer (javax.jms.MessageProducer)79 Message (javax.jms.Message)74 Queue (javax.jms.Queue)66 JMSException (javax.jms.JMSException)64 ActiveMQConnection (org.apache.activemq.ActiveMQConnection)51 ConnectionFactory (javax.jms.ConnectionFactory)47 Destination (javax.jms.Destination)42 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)36 BrokerService (org.apache.activemq.broker.BrokerService)32 CountDownLatch (java.util.concurrent.CountDownLatch)28 Before (org.junit.Before)27 MessageListener (javax.jms.MessageListener)26 CamelContext (org.apache.camel.CamelContext)26 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)23