Search in sources :

Example 1 with JmsConnectionFactory

use of org.apache.qpid.jms.JmsConnectionFactory in project camel by apache.

the class AMQPComponent method amqp10Component.

// Factory methods
/**
     * Use {@code amqpComponent(String uri)} instead.
     */
@Deprecated
public static AMQPComponent amqp10Component(String uri) throws MalformedURLException {
    JmsConnectionFactory connectionFactory = new JmsConnectionFactory(uri);
    connectionFactory.setTopicPrefix("topic://");
    return new AMQPComponent(connectionFactory);
}
Also used : JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory)

Example 2 with JmsConnectionFactory

use of org.apache.qpid.jms.JmsConnectionFactory in project ddf by codice.

the class AmqpProducerConsumerExample method createCamelContext.

private void createCamelContext() throws Exception {
    CamelContext camelContext = getContext();
    JmsConnectionFactory connectionFactory = new JmsConnectionFactory("admin", "admin", "amqps://localhost:5671");
    JmsComponent jms = JmsComponent.jmsComponent(connectionFactory);
    AMQPComponent amqp = new AMQPComponent(connectionFactory);
    camelContext.addComponent("jms", jms);
    camelContext.addComponent("amqp", amqp);
}
Also used : CamelContext(org.apache.camel.CamelContext) JmsComponent(org.apache.camel.component.jms.JmsComponent) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) AMQPComponent(org.apache.camel.component.amqp.AMQPComponent)

Example 3 with JmsConnectionFactory

use of org.apache.qpid.jms.JmsConnectionFactory in project syndesis by syndesisio.

the class AMQPConnector method lookupComponent.

private AMQPComponent lookupComponent() {
    final CamelContext context = getCamelContext();
    final List<String> names = context.getComponentNames();
    if (ObjectHelper.isEmpty(names)) {
        return null;
    }
    // lookup existing component with same configuration
    for (String name : names) {
        Component cmp = context.getComponent(name, false, false);
        if (cmp instanceof AMQPComponent) {
            final ConnectionFactory factory;
            try {
                factory = ((AMQPComponent) cmp).getConfiguration().getConnectionFactory();
            } catch (IllegalArgumentException e) {
                // ignore components without a connection factory
                continue;
            }
            if (factory instanceof JmsConnectionFactory) {
                JmsConnectionFactory jmsConnectionFactory = (JmsConnectionFactory) factory;
                if (!Objects.equals(connectionUri, jmsConnectionFactory.getRemoteURI())) {
                    continue;
                }
                if (!Objects.equals(username, jmsConnectionFactory.getUsername())) {
                    continue;
                }
                if (!Objects.equals(password, jmsConnectionFactory.getPassword())) {
                    continue;
                }
                if (!Objects.equals(clientId, jmsConnectionFactory.getClientID())) {
                    continue;
                }
                return (AMQPComponent) cmp;
            }
        }
    }
    return null;
}
Also used : CamelContext(org.apache.camel.CamelContext) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) AMQPComponent(org.apache.camel.component.amqp.AMQPComponent) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) Component(org.apache.camel.Component) ComponentProxyComponent(io.syndesis.integration.component.proxy.ComponentProxyComponent) AMQPComponent(org.apache.camel.component.amqp.AMQPComponent)

Example 4 with JmsConnectionFactory

use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.

the class ConsumerTest method createFactory.

private ConnectionFactory createFactory(int protocol) {
    switch(protocol) {
        case // core protocol
        1:
            // core protocol
            ActiveMQConnectionFactory coreCF = new ActiveMQConnectionFactory();
            coreCF.setCompressLargeMessage(true);
            coreCF.setMinLargeMessageSize(10 * 1024);
            return coreCF;
        // amqp
        case 2:
            return new JmsConnectionFactory("amqp://localhost:61616");
        // openwire
        case 3:
            return new org.apache.activemq.ActiveMQConnectionFactory("tcp://localhost:61616");
        default:
            return null;
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory)

Example 5 with JmsConnectionFactory

use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.

the class TopicDurableTests method testMessageDurableSubscription.

@Test
public void testMessageDurableSubscription() throws Exception {
    JmsConnectionFactory connectionFactory = new JmsConnectionFactory(getBrokerQpidJMSConnectionURI() + "?jms.clientID=jmsTopicClient");
    Connection connection = connectionFactory.createConnection();
    connection.start();
    System.out.println("testMessageDurableSubscription");
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Topic testTopic = session.createTopic("jmsTopic");
    String sub1ID = "sub1DurSub";
    String sub2ID = "sub2DurSub";
    MessageConsumer subscriber1 = session.createDurableSubscriber(testTopic, sub1ID);
    MessageConsumer subscriber2 = session.createDurableSubscriber(testTopic, sub2ID);
    MessageProducer messageProducer = session.createProducer(testTopic);
    int count = 100;
    String batchPrefix = "First";
    List<Message> listMsgs = generateMessages(session, batchPrefix, count);
    sendMessages(messageProducer, listMsgs);
    System.out.println("First batch messages sent");
    List<Message> recvd1 = receiveMessages(subscriber1, count);
    List<Message> recvd2 = receiveMessages(subscriber2, count);
    assertThat(recvd1.size(), is(count));
    assertMessageContent(recvd1, batchPrefix);
    System.out.println(sub1ID + " :First batch messages received");
    assertThat(recvd2.size(), is(count));
    assertMessageContent(recvd2, batchPrefix);
    System.out.println(sub2ID + " :First batch messages received");
    subscriber1.close();
    System.out.println(sub1ID + " : closed");
    batchPrefix = "Second";
    listMsgs = generateMessages(session, batchPrefix, count);
    sendMessages(messageProducer, listMsgs);
    System.out.println("Second batch messages sent");
    recvd2 = receiveMessages(subscriber2, count);
    assertThat(recvd2.size(), is(count));
    assertMessageContent(recvd2, batchPrefix);
    System.out.println(sub2ID + " :Second batch messages received");
    subscriber1 = session.createDurableSubscriber(testTopic, sub1ID);
    System.out.println(sub1ID + " :connected");
    recvd1 = receiveMessages(subscriber1, count);
    assertThat(recvd1.size(), is(count));
    assertMessageContent(recvd1, batchPrefix);
    System.out.println(sub1ID + " :Second batch messages received");
    subscriber1.close();
    subscriber2.close();
    session.unsubscribe(sub1ID);
    session.unsubscribe(sub2ID);
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) Topic(javax.jms.Topic) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

JmsConnectionFactory (org.apache.qpid.jms.JmsConnectionFactory)40 Connection (javax.jms.Connection)19 Session (javax.jms.Session)19 MessageConsumer (javax.jms.MessageConsumer)17 MessageProducer (javax.jms.MessageProducer)17 Test (org.junit.Test)17 TextMessage (javax.jms.TextMessage)14 ConnectionFactory (javax.jms.ConnectionFactory)10 Queue (javax.jms.Queue)10 Message (javax.jms.Message)8 BytesMessage (javax.jms.BytesMessage)4 JmsConnection (org.apache.qpid.jms.JmsConnection)4 JMSException (javax.jms.JMSException)3 Topic (javax.jms.Topic)3 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 AMQPComponent (org.apache.camel.component.amqp.AMQPComponent)3 URI (java.net.URI)2 JMSSecurityException (javax.jms.JMSSecurityException)2 InitialContext (javax.naming.InitialContext)2 Configuration (org.apache.activemq.artemis.core.config.Configuration)2