Search in sources :

Example 66 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project play-cookbook by spinscale.

the class ActiveMqTest method initialize.

@Before
public void initialize() throws Exception {
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_USER, ActiveMQConnection.DEFAULT_PASSWORD, ActiveMQConnection.DEFAULT_BROKER_URL);
    receiveConnection = connectionFactory.createTopicConnection();
    receiveConnection.start();
    receiveSession = receiveConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    receiveTopic = receiveSession.createTopic("playMessages");
    receiveSubscriber = receiveSession.createSubscriber(receiveTopic);
    sendingConnection = connectionFactory.createTopicConnection();
    sendingConnection.start();
    sendingSession = sendingConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    sendingTopic = sendingSession.createTopic("playMessages");
    sendingPublisher = sendingSession.createPublisher(sendingTopic);
    ChatRoom.clean();
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Before(org.junit.Before)

Example 67 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project opennms by OpenNMS.

the class SimpleJobPublisher method publishJob.

// Name of the queue we will be sending messages to
// private static String subject = "TESTQUEUE";
@Override
public void publishJob(CollectionJob job, String site) {
    try {
        // Getting JMS connection from the server and starting it
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
        Connection connection = connectionFactory.createConnection();
        connection.start();
        // JMS messages are sent and received using a Session. We will
        // create here a non-transactional session object. If you want
        // to use transactions you should set the first parameter to 'true'
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        // Destination represents here our queue 'TESTQUEUE' on the
        // JMS server. You don't have to do anything special on the
        // server to create it, it will be created automatically.
        Destination destination = session.createQueue(site);
        // MessageProducer is used for sending messages (as opposed
        // to MessageConsumer which is used for receiving them)
        MessageProducer producer = session.createProducer(destination);
        // We will send a small text message saying 'Hello' in Japanese
        ObjectMessage message = session.createObjectMessage(job);
        // Here we are sending the message!
        producer.send(message);
        logger.info("Sent message '{}'", ((CollectionJob) message.getObject()).toString());
        connection.close();
    } catch (Exception e) {
        logger.error("Exception during Job Publishing, sorry '{}'", e.getMessage());
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ActiveMQConnection(org.apache.activemq.ActiveMQConnection)

Example 68 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project oxAuth by GluuFederation.

the class ApplicationAuditLogger method tryToEstablishJMSConnectionImpl.

private boolean tryToEstablishJMSConnectionImpl() {
    destroy();
    Set<String> jmsBrokerURISet = getJmsBrokerURISet();
    if (BooleanUtils.isNotTrue(isEnabledOAuthAuditnLogging()) || CollectionUtils.isEmpty(jmsBrokerURISet))
        return false;
    this.jmsBrokerURISet = new HashSet<String>(jmsBrokerURISet);
    this.jmsUserName = getJmsUserName();
    this.jmsPassword = getJmsPassword();
    Iterator<String> jmsBrokerURIIterator = jmsBrokerURISet.iterator();
    StringBuilder uriBuilder = new StringBuilder();
    while (jmsBrokerURIIterator.hasNext()) {
        String jmsBrokerURI = jmsBrokerURIIterator.next();
        uriBuilder.append("tcp://");
        uriBuilder.append(jmsBrokerURI);
        if (jmsBrokerURIIterator.hasNext())
            uriBuilder.append(",");
    }
    String brokerUrl = BROKER_URL_PREFIX + uriBuilder + BROKER_URL_SUFFIX;
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(this.jmsUserName, this.jmsPassword, brokerUrl);
    this.pooledConnectionFactory = new PooledConnectionFactory(connectionFactory);
    pooledConnectionFactory.setIdleTimeout(5000);
    pooledConnectionFactory.setMaxConnections(10);
    pooledConnectionFactory.start();
    return true;
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) PooledConnectionFactory(org.apache.activemq.pool.PooledConnectionFactory)

Example 69 with ActiveMQConnectionFactory

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

the class ActiveMQResourceAdapter method createConnectionFactory.

@Override
protected ActiveMQConnectionFactory createConnectionFactory(final ActiveMQConnectionRequestInfo connectionRequestInfo, final MessageActivationSpec activationSpec) {
    if (TomEEMessageActivationSpec.class.isInstance(activationSpec)) {
        final TomEEMessageActivationSpec s = TomEEMessageActivationSpec.class.cast(activationSpec);
        if (s.getConnectionFactoryLookup() != null) {
            try {
                final Object lookup = SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext().lookup("openejb:Resource/" + s.getConnectionFactoryLookup());
                if (ActiveMQConnectionFactory.class.isInstance(lookup)) {
                    return ActiveMQConnectionFactory.class.cast(lookup);
                }
                // already handled
                return ActiveMQConnectionFactory.class.cast(lookup);
            } catch (final NamingException e) {
                throw new IllegalArgumentException("");
            }
        }
    }
    final ActiveMQConnectionFactory factory = new TomEEConnectionFactory();
    connectionRequestInfo.configure(factory, activationSpec);
    return factory;
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) TomEEConnectionFactory(org.apache.openejb.resource.activemq.jms2.TomEEConnectionFactory) NamingException(javax.naming.NamingException)

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