Search code examples
jmsweblogicjndiweblogic-10.x

How to configure JNDI symlink in WebLogic


In short I want to make the same object (namely JMS topic) available simultaneously by two JNDI names (one of those will be used for only posting messages and the other only for listening).

If there's no way to create a JNDI symlink, then any other way to make messages posted into A appear in B will work for me as well.

The reason is that I have some legacy code that subscribes to topic B and writes to topic A and I cannot change that code.
Then on some servers I need A and B to be one and the same in order to let one piece of code receive messages sent by another piece of code directly while on other servers A and B can be configured to refer to some external resources.


Solution

  • After a lot of experimenting I made it work by configuring a Foreign Server with mappings for the JMS topic and its connection factory.

    Here's a wlst script illustrating my configuration:

    startEdit()
    
    cd('/')
    mod = 'loopback'
    module = cmo.createJMSSystemResource(mod)
    module.setTargets(cmo.getClusters())
    
    server = module.createForeignServer('loopback_server')
    server.setDefaultTargetingEnabled(true)
    server.setInitialContextFactory('weblogic.jndi.WLInitialContextFactory')
    # When we don't populate connection parameters (URLs, user, password),
    # WebLogic defaults to connecting to the current cluster, which is exactly what we need!
    
    topicLink = server.createForeignDestination('A_to_B')
    topicLink.setLocalJNDIName('jms/B/topic')
    topicLink.setRemoteJNDIName('jms/A/topic')
    cfLink = server.createForeignConnectionFactory('A_to_B_cf')
    cfLink.setLocalJNDIName('jms/B/connectionfactory')
    cfLink.setRemoteJNDIName('jms/A/connectionfactory')
    
    activate()
    

    P.S.: the code above was created by putting together crucial lines from my huge wlst script setting up all my JMS resources, so there's a possibility that it won't just work as is