Wednesday, November 13, 2013

Configuring LDAP failover with Fuse/A-MQ

When using the org.apache.karaf.jaas.modules.ldap.LDAPLoginModule in the Karaf container it is possible to configure one or mode provider URLS to connect to.

The JVM supports multiple providers as detailed in the JndiTutorial

Then just add the multiple providers into the LDAPLoginModule config e.g.

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:jaas="http://karaf.apache.org/xmlns/jaas/v1.0.0"
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">
<jaas:config name="JAASMultiLdap" rank="1">
<jaas:module className="org.apache.karaf.jaas.modules.ldap.LDAPLoginModule"
flags="required">
initialContextFactory=com.sun.jndi.ldap.LdapCtxFactory
connection.username=cn=Manager,dc=redhat,dc=com
connection.password=mytestPW
connection.url=" ldap://192.168.2.10:389 ldap://192.168.1.132:389 "
user.base.dn=ou=Users,dc=redhat,dc=com
user.filter=(uid=%u)
user.search.subtree = true
role.base.dn=ou=roles,dc=redhat,dc=com
role.filter=(member:=uid=%u)
role.name.attribute=cn
role.search.subtree = true
authentication = simple
</jaas:module>
</jaas:config>
</blueprint>

The multiple providers are specified in the connection.url property. 
Note the spaces around the LDAP urls are critical to how Karaf and subsequently the JNDI context parses the list of urls. 

There should be a space at the start of the list after the " and one before the end quote.

Monday, April 8, 2013

Camel AMQP component and MRG-M/QPID

The Camel AMQP component documentation here is pretty basic when it comes to demonstrating how to integrate camel and qpid. It basically shows the URL structure and not much more.

IMHO the most powerful aspects of AMQP 0.10 is the concepts of exchanges and routing/binding keys and the flexibility that these features provide when building messaging solutions.

 To use an AMQP 0.10 address in camel just specify it as you would in a normal java application.

 For example, the following route will create an auto-delete queue on the default exchange
<route id="ampqIN">
    <from uri="amqp:queue:TestQueueIN;{create:always,node:{x-declare:{auto-delete:True}}}?concurrentConsumers=1&amp;jmsKeyFormatStrategy=passthrough"/>
    <log message="The current message contains ${headers} ${body}"/>
    <to uri="amqp:topic:amq.topic?concurrentConsumers=1&amp;jmsKeyFormatStrategy=passthrough"/>
</route>

The following example specifies an address using an exchange/subject pair
    <camelContext trace="false" id="blueprintContext"
        xmlns="http://camel.apache.org/schema/blueprint">
        <route id="ampqIN">
            <from
                uri="amqp:queue:nocexc/TestQueueIN?concurrentConsumers=1&amp;jmsKeyFormatStrategy=passthrough" />
            <log message="The current message contains ${headers} ${body}" />
            <to
                uri="amqp:queue:TestExchange/?concurrentConsumers=1&amp;jmsKeyFormatStrategy=passthrough" />
        </route>
    </camelContext>

You can also specify the exchange & routing keys using multiple formats:


<!--  <to uri="amqp:queue:BURL:fanout://TestExc//Boing?concurrentConsumers=1&amp;jmsKeyFormatStrategy=passthrough"/>-->
        <to uri="amqp:queue:testq;{create:never,node:{type:queue,durable:True,x-bindings:[{exchange: TextExc}]}}?concurrentConsumers=1&amp;jmsKeyFormatStrategy=passthrough"/>