Search in sources :

Example 6 with ActiveMQConnectionFactory

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

the class JMSClient method sendToActiveMQ.

private static void sendToActiveMQ(String value) throws Exception {
    ConnectionFactory cf = new ActiveMQConnectionFactory(AMQ_USER, AMQ_PASSWD, AMQ_BROKER_URL);
    Connection conn = cf.createConnection();
    try {
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        final MessageProducer producer = session.createProducer(session.createQueue(REQUEST_NAME));
        final MessageConsumer consumer = session.createConsumer(session.createQueue(REPLY_NAME));
        conn.start();
        producer.send(session.createTextMessage(createPayload(value)));
        System.out.println("Message sent. Waiting for reply ...");
        Message message = consumer.receive(3000);
        String reply = ((TextMessage) message).getText();
        System.out.println("REPLY: \n" + reply);
    } finally {
        conn.close();
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Example 7 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 8 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)

Example 9 with ActiveMQConnectionFactory

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

the class ActiveMQPropertiesTests method setTrustedPackages.

@Test
public void setTrustedPackages() {
    this.properties.getPackages().setTrustAll(false);
    this.properties.getPackages().getTrusted().add("trusted.package");
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactoryFactory(this.properties).createConnectionFactory(ActiveMQConnectionFactory.class);
    assertThat(factory.isTrustAllPackages()).isEqualTo(false);
    assertThat(factory.getTrustedPackages().size()).isEqualTo(1);
    assertThat(factory.getTrustedPackages().get(0)).isEqualTo("trusted.package");
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Test(org.junit.Test)

Example 10 with ActiveMQConnectionFactory

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

the class JmsAutoConfigurationTests method testActiveMQOverriddenPool.

@Test
public void testActiveMQOverriddenPool() {
    load(TestConfiguration.class, "spring.activemq.pool.enabled:true");
    JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
    PooledConnectionFactory pool = this.context.getBean(PooledConnectionFactory.class);
    assertThat(jmsTemplate).isNotNull();
    assertThat(pool).isNotNull();
    assertThat(pool).isEqualTo(jmsTemplate.getConnectionFactory());
    ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) pool.getConnectionFactory();
    assertThat(factory.getBrokerURL()).isEqualTo(ACTIVEMQ_EMBEDDED_URL);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) JmsTemplate(org.springframework.jms.core.JmsTemplate) PooledConnectionFactory(org.apache.activemq.pool.PooledConnectionFactory) Test(org.junit.Test)

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