Search in sources :

Example 21 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 22 with JmsConnectionFactory

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

the class AMQPComponent method amqpComponent.

public static AMQPComponent amqpComponent(String uri) {
    JmsConnectionFactory connectionFactory = new JmsConnectionFactory(uri);
    connectionFactory.setTopicPrefix("topic://");
    return new AMQPComponent(connectionFactory);
}
Also used : JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory)

Example 23 with JmsConnectionFactory

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

the class AMQPComponent method doStart.

// Life-cycle
@Override
protected void doStart() throws Exception {
    Set<AMQPConnectionDetails> connectionDetails = getCamelContext().getRegistry().findByType(AMQPConnectionDetails.class);
    if (connectionDetails.size() == 1) {
        AMQPConnectionDetails details = connectionDetails.iterator().next();
        JmsConnectionFactory connectionFactory = new JmsConnectionFactory(details.username(), details.password(), details.uri());
        connectionFactory.setTopicPrefix("topic://");
        setConnectionFactory(connectionFactory);
    }
    super.doStart();
}
Also used : JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory)

Example 24 with JmsConnectionFactory

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

the class DivertTopicToQueueTest method divertTopicToQueueWithSelectorTest.

@Test
public void divertTopicToQueueWithSelectorTest() throws Exception {
    final String address1 = "bss.order.workorderchanges.v1.topic";
    final String address2 = "bss.order.Consumer.cbma.workorderchanges.v1.queue";
    final String address3 = "bss.order.Consumer.pinpoint.workorderchanges.v1.queue";
    DivertConfiguration dc1 = new DivertConfiguration().setName("WorkOrderChangesCBMA-Divert").setRoutingName("WorkOrderChangesCBMA-Divert").setAddress(address1).setForwardingAddress(address2).setExclusive(false).setRoutingType(DivertConfigurationRoutingType.ANYCAST);
    DivertConfiguration dc2 = new DivertConfiguration().setName("WorkOrderChangesPinpoint-Divert").setRoutingName("WorkOrderChangesPinpoint-Divert").setAddress(address1).setForwardingAddress(address3).setExclusive(false).setRoutingType(DivertConfigurationRoutingType.ANYCAST);
    server.deployDivert(dc1);
    server.deployDivert(dc2);
    JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerQpidJMSConnectionURI());
    Connection connection = factory.createConnection(null, null);
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    javax.jms.Topic topicSource = session.createTopic(address1);
    javax.jms.Queue queueTarget = session.createQueue(address2);
    javax.jms.Queue queueTarget2 = session.createQueue(address3);
    final MessageProducer producer = session.createProducer(topicSource);
    final TextMessage message = session.createTextMessage("Hello");
    message.setStringProperty("filename", "BILHANDLE");
    connection.start();
    String selector = "filename='BILHANDLE'";
    final MessageConsumer consumer = session.createConsumer(queueTarget, selector);
    final MessageConsumer consumer2 = session.createConsumer(queueTarget2, selector);
    producer.send(message);
    TextMessage receivedMessage = (TextMessage) consumer.receive(1000);
    TextMessage receivedMessage2 = (TextMessage) consumer2.receive(1000);
    Assert.assertNotNull(receivedMessage);
    Assert.assertNotNull(receivedMessage2);
    connection.close();
}
Also used : MessageConsumer(javax.jms.MessageConsumer) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 25 with JmsConnectionFactory

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

the class JMSClientTestSupport method createConnection.

private Connection createConnection(URI remoteURI, String username, String password, String clientId, boolean start) throws JMSException {
    JmsConnectionFactory factory = new JmsConnectionFactory(remoteURI);
    Connection connection = trackJMSConnection(factory.createConnection(username, password));
    connection.setExceptionListener(new ExceptionListener() {

        @Override
        public void onException(JMSException exception) {
            exception.printStackTrace();
        }
    });
    if (clientId != null && !clientId.isEmpty()) {
        connection.setClientID(clientId);
    }
    if (start) {
        connection.start();
    }
    return connection;
}
Also used : JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) Connection(javax.jms.Connection) ExceptionListener(javax.jms.ExceptionListener) JMSException(javax.jms.JMSException)

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