Search in sources :

Example 41 with ActiveMQConnectionFactory

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

the class Jms method sjms.

@Produces
@Named("sjms")
@ApplicationScoped
SjmsComponent sjms() {
    SjmsComponent component = new SjmsComponent();
    component.setConnectionFactory(new ActiveMQConnectionFactory("vm://broker?broker.persistent=false&broker.useShutdownHook=false&broker.useJmx=false"));
    component.setConnectionCount(maxConnections);
    return component;
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) SjmsComponent(org.apache.camel.component.sjms.SjmsComponent) Named(javax.inject.Named) Produces(javax.enterprise.inject.Produces) ApplicationScoped(javax.enterprise.context.ApplicationScoped)

Example 42 with ActiveMQConnectionFactory

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

the class CamelJmsTestHelper method createPersistentConnectionFactory.

public static ConnectionFactory createPersistentConnectionFactory(String options) {
    // using a unique broker name improves testing when running the entire test suite in the same JVM
    int id = counter.incrementAndGet();
    // use an unique data directory in target
    String dir = "target/activemq-data-" + id;
    // remove dir so its empty on startup
    FileUtil.removeDir(new File(dir));
    String url = "vm://test-broker-" + id + "?broker.persistent=true&broker.useJmx=false&broker.dataDirectory=" + dir;
    if (options != null) {
        url = url + "&" + options;
    }
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
    // optimize AMQ to be as fast as possible so unit testing is quicker
    connectionFactory.setCopyMessageOnSend(false);
    connectionFactory.setOptimizeAcknowledge(true);
    connectionFactory.setOptimizedMessageDispatch(true);
    connectionFactory.setUseAsyncSend(true);
    connectionFactory.setAlwaysSessionAsync(false);
    connectionFactory.setTrustAllPackages(true);
    // use a pooled connection factory
    PooledConnectionFactory pooled = new PooledConnectionFactory(connectionFactory);
    pooled.setMaxConnections(8);
    return pooled;
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) PooledConnectionFactory(org.apache.activemq.pool.PooledConnectionFactory) File(java.io.File)

Example 43 with ActiveMQConnectionFactory

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

the class TestNotificationListener method setUp.

@Before
public void setUp() throws Exception {
    System.setProperty("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
    System.setProperty("java.naming.provider.url", "vm://localhost?broker.persistent=false");
    ConnectionFactory connFac = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
    Connection conn = connFac.createConnection();
    conn.start();
    // We want message to be sent when session commits, thus we run in
    // transacted mode.
    Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
    Destination hcatTopic = session.createTopic(HCatConstants.HCAT_DEFAULT_TOPIC_PREFIX);
    MessageConsumer consumer1 = session.createConsumer(hcatTopic);
    consumer1.setMessageListener(this);
    Destination tblTopic = session.createTopic(HCatConstants.HCAT_DEFAULT_TOPIC_PREFIX + ".mydb.mytbl");
    MessageConsumer consumer2 = session.createConsumer(tblTopic);
    consumer2.setMessageListener(this);
    Destination dbTopic = session.createTopic(HCatConstants.HCAT_DEFAULT_TOPIC_PREFIX + ".mydb");
    MessageConsumer consumer3 = session.createConsumer(dbTopic);
    consumer3.setMessageListener(this);
    setUpHiveConf();
    hiveConf.set(ConfVars.METASTORE_EVENT_LISTENERS.varname, NotificationListener.class.getName());
    hiveConf.setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, "org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory");
    SessionState.start(new CliSessionState(hiveConf));
    driver = new Driver(hiveConf);
    client = new HiveMetaStoreClient(hiveConf);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Destination(javax.jms.Destination) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) HiveMetaStoreClient(org.apache.hadoop.hive.metastore.HiveMetaStoreClient) Connection(javax.jms.Connection) Driver(org.apache.hadoop.hive.ql.Driver) CliSessionState(org.apache.hadoop.hive.cli.CliSessionState) Session(javax.jms.Session) Before(org.junit.Before)

Example 44 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project quickstarts by jboss-switchyard.

the class JMSClient method sendToActiveMQ.

private static void sendToActiveMQ(String payload, String queueName) throws Exception {
    ConnectionFactory cf = new ActiveMQConnectionFactory(AMQ_USER, AMQ_PASSWD, AMQ_BROKER_URL);
    Connection conn = cf.createConnection();
    conn.start();
    try {
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer(session.createQueue(queueName));
        producer.send(session.createTextMessage(payload));
        session.close();
        verifyOutputQueue(conn.createSession(false, Session.AUTO_ACKNOWLEDGE));
    } finally {
        conn.close();
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session)

Example 45 with ActiveMQConnectionFactory

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

the class SjmsBatchConsumerAsyncStartTest method createCamelContext.

// lets just test that any of the existing tests works
@Override
public CamelContext createCamelContext() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    registry.put("testStrategy", new ListAggregationStrategy());
    ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(broker.getTcpConnectorUri());
    SjmsComponent sjmsComponent = new SjmsComponent();
    sjmsComponent.setConnectionFactory(connectionFactory);
    SjmsBatchComponent sjmsBatchComponent = new SjmsBatchComponent();
    sjmsBatchComponent.setConnectionFactory(connectionFactory);
    // turn on async start listener
    sjmsBatchComponent.setAsyncStartListener(true);
    CamelContext context = new DefaultCamelContext(registry);
    context.addComponent("sjms", sjmsComponent);
    context.addComponent("sjms-batch", sjmsBatchComponent);
    return context;
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ConnectionFactory(javax.jms.ConnectionFactory) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) SjmsComponent(org.apache.camel.component.sjms.SjmsComponent) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

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